package com.ss.android.article.base.feature.app.b;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;

import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.model.PraiseData;
import com.ss.android.article.base.feature.feed.presenter.ArticleQueryObj;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.base.feature.model.MediaInfo;
import com.ss.android.article.base.feature.model.UgcUser;
import com.ss.android.article.base.feature.subscribe.model.EntryGroup;
import com.ss.android.article.base.feature.subscribe.model.EntryItem;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.common.AbsApiThread;
import com.ss.android.d.SSDBHelper;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.model.AbsArticle;
import com.ss.android.model.ItemType;
import com.ss.android.model.f;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class DBHelper extends a {
    final class DBOpenHelper extends SQLiteOpenHelper {
        public DBOpenHelper(Context context) {
            super(context, "lite_article.db", null, 46);
        }

        public final void onCreate(SQLiteDatabase database) {
            try {
                database.execSQL("CREATE TABLE v30_article ( _id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR NOT NULL, item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, tag VARCHAR, level INTEGER NOT NULL DEFAULT 0, behot_time INTEGER NOT NULL, share_url VARCHAR, digg_count INTEGER NOT NULL, bury_count INTEGER NOT NULL, repin_count INTEGER NOT NULL, comment_count INTEGER NOT NULL, user_digg INTEGER, user_bury INTEGER, user_repin INTEGER, user_repin_time INTEGER, source VARCHAR, title VARCHAR, url VARCHAR, city VARCHAR, keywords VARCHAR, publish_time INTEGER, hot INTEGER NOT NULL DEFAULT 0, tip INTEGER NOT NULL DEFAULT 0, has_image INTEGER NOT NULL DEFAULT 0, has_video INTEGER NOT NULL DEFAULT 0, abstract TEXT, image_list TEXT, comment_json TEXT, large_image_json TEXT, middle_image_json TEXT, group_type INTEGER NOT NULL DEFAULT 0, subject_label VARCHAR, item_version INTEGER NOT NULL DEFAULT 0, subject_group_id INTEGER NOT NULL DEFAULT 0, article_type INTEGER NOT NULL DEFAULT 0, article_sub_type INTEGER NOT NULL DEFAULT 0, article_url VARCHAR, article_alt_url VARCHAR, display_url VARCHAR, display_title VARCHAR, preload_web INTEGER NOT NULL DEFAULT 0, ban_comment INTEGER NOT NULL DEFAULT 0, natant_level INTEGER NOT NULL DEFAULT 0,group_flags INTEGER NOT NULL DEFAULT 0,tc_head_text TEXT, open_url VARCHAR, read_timestamp INTEGER, web_type_loadtime INTEGER NOT NULL DEFAULT 0, web_tc_loadtime INTEGER NOT NULL DEFAULT 0, stats_timestamp INTEGER, from_stream INTEGER NOT NULL DEFAULT 0, max_behot_time INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, user_dislike_time INTEGER NOT NULL DEFAULT 0, flag_dislike INTEGER NOT NULL DEFAULT 0, flag_repin INTEGER NOT NULL DEFAULT 0, flag_digg INTEGER NOT NULL DEFAULT 0, user_digg_time INTEGER NOT NULL DEFAULT 0, ext_json TEXT )");
                database.execSQL(" CREATE TABLE v30_detail ( _id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL DEFAULT 0, item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, content TEXT, timestamp INTEGER, expire_seconds INTEGER, cache_token VARCHAR, image_detail TEXT, thumb_image TEXT, ext_json TEXT, serial_data TEXT )");
                database.execSQL("CREATE TABLE v30_category_list (_id INTEGER PRIMARY KEY AUTOINCREMENT, category VARCHAR NOT NULL, cell_id VARCHAR NOT NULL, cell_type INTEGER NOT NULL DEFAULT -1, cell_data TEXT, ad_id INTEGER DEFAULT 0, cate_cursor INTEGER NOT NULL DEFAULT 0, cate_behot_time INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE INDEX idx_stream ON v30_article (item_id, group_item_id)");
                database.execSQL("CREATE INDEX idx_stream_rank ON v30_article (behot_time DESC)");
                database.execSQL("CREATE INDEX idx_category ON v30_category_list (category, cell_id, cell_type)");
                database.execSQL("CREATE INDEX idx_category_rank ON v30_category_list (category, cate_behot_time DESC)");
                database.execSQL("CREATE INDEX idx_max_behot ON v30_article ( max_behot_time DESC)");
                database.execSQL("CREATE TABLE v30_essay ( _id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR NOT NULL, item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, tag VARCHAR, level INTEGER NOT NULL DEFAULT 0, behot_time INTEGER, share_url VARCHAR, digg_count INTEGER, bury_count INTEGER, repin_count INTEGER, comment_count INTEGER , user_digg INTEGER, user_bury INTEGER,user_repin INTEGER,user_repin_time INTEGER, content TEXT, create_time INTEGER, large_image TEXT, middle_image TEXT, god_comments TEXT, group_flags INTERGER NOT NULL DEFAULT 0, display_type INTERGER NOT NULL DEFAULT 0, stats_timestamp INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, max_behot_time INTEGER NOT NULL DEFAULT 0, read_timestamp INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE TABLE city (name VARCHAR NOT NULL, pinyin VARCHAR NOT NULL )");
                database.execSQL("CREATE INDEX idx_essay ON v30_essay (item_id)");
                database.execSQL("CREATE INDEX idx_essay_time ON v30_essay (behot_time DESC)");
                database.execSQL("CREATE TABLE item_action (item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, action INTEGER NOT NULL, timestamp INTEGER NOT NULL,  PRIMARY KEY (item_id, group_item_id, action) );");
                database.execSQL("CREATE TABLE item_action_v3 (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, target_type INTEGER NOT NULL, action VARCHAR NOT NULL, timestamp INTEGER NOT NULL, extra_data TEXT NOT NULL );");
                database.execSQL("CREATE INDEX idx_action_time ON item_action (timestamp)");
                database.execSQL("CREATE TABLE article_category (category VARCHAR NOT NULL, last_refresh_time INTEGER NOT NULL DEFAULT 0, last_loadmore_time INTEGER NOT NULL DEFAULT 0, top_time INTEGER NOT NULL DEFAULT 0, bottom_time INTEGER NOT NULL DEFAULT 0  )");
                database.execSQL("CREATE TABLE update_list_meta ( user_id INTEGER PRIMARY KEY, top_cursor INTEGER NOT NULL, bottom_cursor INTEGER NOT NULL, refresh_time INTEGER NOT NULL )");
                database.execSQL("CREATE TABLE update_item ( user_id INTEGER NOT NULL DEFAULT 0, update_id INTEGER NOT NULL, cursor INTEGER NOT NULL, create_time INTEGER NOT NULL, flags INTEGER NOT NULL, reason VARCHAR, item_json TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE TABLE forum_item ( id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, extra TEXT, fresh_time INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE TABLE IF NOT EXISTS impression (key_name VARCHAR, list_type INTEGER NOT NULL DEFAULT 0, session_id INTEGER NOT NULL DEFAULT 0, impression TEXT, extra TEXT )");
                database.execSQL(" CREATE TABLE search_word ( id INTEGER PRIMARY KEY AUTOINCREMENT, type INTEGER, search_word VARCHAR, timestamp INTEGER )");
                database.execSQL("CREATE INDEX idx_suggestion_time ON search_word (timestamp DESC)");
                database.execSQL(" CREATE TABLE v27_entry ( id INTEGER PRIMARY KEY, type INTEGER NOT NULL DEFAULT 0, name VARCHAR NOT NULL, description VARCHAR, icon VARCHAR, subscribe_count INTEGER NOT NULL DEFAULT 0, tip_new INTEGER NOT NULL DEFAULT 0, is_subscribe INTEGER NOT NULL DEFAULT 0, wap_url VARCHAR, group_id INTEGER NOT NULL DEFAULT 0, ext_json VARCHAR, user_id INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL(" CREATE TABLE v27_entry_group_meta ( id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, list_order INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL(" CREATE TABLE v27_entry_group ( e_group_id INTEGER NOT NULL, e_entry_id INTEGER NOT NULL, e_list_order INTEGER NOT NULL DEFAULT 0, e_int_value INTEGER, e_str_value VARCHAR, e_time_value INTEGER, e_ext_json VARCHAR,  PRIMARY KEY (e_group_id, e_entry_id) )");
                database.execSQL(" CREATE TABLE misc_kv ( name VARCHAR PRIMARY KEY, int_value INTEGER, str_value VARCHAR, time_value INTEGER, ext_json VARCHAR )");
                database.execSQL("CREATE TABLE IF NOT EXISTS net_request_queue ( key VARCHAR NOT NULL, type INTEGER NOT NULL DEFAULT 0, url VARCHAR, request_method INTEGER, entity_json VARCHAR,time INTEGER NOT NULL,retry_count INTEGER,extra VARCHAR , PRIMARY KEY (type,key,time ) )");
                database.execSQL("CREATE TABLE IF NOT EXISTS subscribed_video_pgc_user ( id INTEGER PRIMARK KEY, avatarUrl VARCHAR, modify_time INTEGER DEFAULT 0, description VARCHAR, extraJson VARCHAR, name VARCHAR, scheme VARCHAR, user_verified INTEGER )");
                database.execSQL("CREATE TABLE v38_post ( _id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL, item_id INTEGER NOT NULL, key VARCHAR NOT NULL, title VARCHAR, content TEXT, schema TEXT, inner_ui_flag INTEGER, behot_time INTEGER, share_url VARCHAR, digg_count INTEGER, bury_count INTEGER, repin_count INTEGER, comment_count INTEGER, user_digg INTEGER, user_bury INTEGER, user_repin INTEGER, user_repin_time INTEGER, large_image_list TEXT, thumb_image_list TEXT, forum TEXT, user TEXT, friend_digg_list TEXT, comments TEXT, group_json TEXT, position_json TEXT, stats_timestamp INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, read_timestamp INTEGER NOT NULL DEFAULT 0, score REAL NOT NULL DEFAULT 0.0 )");
                database.execSQL("CREATE INDEX idx_post_id ON v38_post (id)");
                database.execSQL("CREATE INDEX idx_post_item_id ON v38_post (item_id)");
                database.execSQL(" CREATE TABLE v38_category_meta ( _id INTEGER PRIMARY KEY AUTOINCREMENT, concern_id INTEGER, category_name VARCHAR, concern_info TEXT, show_et_status INTEGER, post_content_hint TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE INDEX idx_category_meta_concern_id ON v38_category_meta (concern_id)");
                database.execSQL("CREATE INDEX idx_category_meta_category_name ON v38_category_meta (category_name)");
            } catch (Exception exception) {
                Logger.e("DBHelper", "create db exception " + exception);
            }
        }

        public final void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
            if (oldVersion < 2) {
                try {
                    database.execSQL("DROP TABLE IF EXISTS detail");
                    database.execSQL("DROP TABLE IF EXISTS article");
                } catch (Exception e) {
                    Logger.e("DBHelper", "onUpgrade " + oldVersion + " to " + newVersion + " exception: " + e);
                    return;
                }
            }
            if (oldVersion < 11) {
                database.execSQL("DROP TABLE IF EXISTS category");
            }

            if (oldVersion < 12) {
                database.execSQL("CREATE TABLE city (name VARCHAR NOT NULL, pinyin VARCHAR NOT NULL )");
            }

            if (oldVersion < 15) {
                database.execSQL("CREATE TABLE article_category (category VARCHAR NOT NULL, last_refresh_time INTEGER NOT NULL DEFAULT 0, last_loadmore_time INTEGER NOT NULL DEFAULT 0, top_time INTEGER NOT NULL DEFAULT 0, bottom_time INTEGER NOT NULL DEFAULT 0  )");
            }

            if (oldVersion < 22) {
                database.execSQL("CREATE TABLE update_list_meta ( user_id INTEGER PRIMARY KEY, top_cursor INTEGER NOT NULL, bottom_cursor INTEGER NOT NULL, refresh_time INTEGER NOT NULL )");
                database.execSQL("CREATE TABLE update_item ( user_id INTEGER NOT NULL DEFAULT 0, update_id INTEGER NOT NULL, cursor INTEGER NOT NULL, create_time INTEGER NOT NULL, flags INTEGER NOT NULL, reason VARCHAR, item_json TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
            }

            if (oldVersion < 23) {
                database.execSQL("CREATE TABLE IF NOT EXISTS impression (key_name VARCHAR, list_type INTEGER NOT NULL DEFAULT 0, session_id INTEGER NOT NULL DEFAULT 0, impression TEXT, extra TEXT )");
                database.execSQL(" CREATE TABLE search_word ( id INTEGER PRIMARY KEY AUTOINCREMENT, type INTEGER, search_word VARCHAR, timestamp INTEGER )");
                database.execSQL("CREATE INDEX idx_suggestion_time ON search_word (timestamp DESC)");
            }

            if (oldVersion < 24 && oldVersion >= 22) {
                database.execSQL("ALTER TABLE update_item ADD COLUMN reason VARCHAR");
            }

            if (oldVersion < 25) {
                database.execSQL("DROP TABLE IF EXISTS essay");
                database.execSQL("DROP TABLE IF EXISTS image");
                database.execSQL("DROP TABLE IF EXISTS essay_category");
                database.execSQL("DROP TABLE IF EXISTS image_category");
                database.execSQL("DROP TABLE IF EXISTS info_article");
                database.execSQL("DROP TABLE IF EXISTS info_essay");
                database.execSQL("DROP TABLE IF EXISTS info_detail");
                database.execSQL("DROP TABLE IF EXISTS info_category_list");
                database.execSQL("DROP TABLE IF EXISTS info_category_refresh");
                database.execSQL("DROP TABLE IF EXISTS info_entry");
                database.execSQL("DROP TABLE IF EXISTS info_group_entry");
                database.execSQL("DROP TABLE IF EXISTS info_city_entry");
                database.execSQL("DROP TABLE IF EXISTS tag_list");
            }

            if (oldVersion < 27) {
                database.execSQL(" CREATE TABLE v27_entry ( id INTEGER PRIMARY KEY, type INTEGER NOT NULL DEFAULT 0, name VARCHAR NOT NULL, description VARCHAR, icon VARCHAR, subscribe_count INTEGER NOT NULL DEFAULT 0, tip_new INTEGER NOT NULL DEFAULT 0, is_subscribe INTEGER NOT NULL DEFAULT 0, wap_url VARCHAR, group_id INTEGER NOT NULL DEFAULT 0, ext_json VARCHAR, user_id INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL(" CREATE TABLE v27_entry_group_meta ( id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, list_order INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL(" CREATE TABLE v27_entry_group ( e_group_id INTEGER NOT NULL, e_entry_id INTEGER NOT NULL, e_list_order INTEGER NOT NULL DEFAULT 0, e_int_value INTEGER, e_str_value VARCHAR, e_time_value INTEGER, e_ext_json VARCHAR,  PRIMARY KEY (e_group_id, e_entry_id) )");
                database.execSQL(" CREATE TABLE misc_kv ( name VARCHAR PRIMARY KEY, int_value INTEGER, str_value VARCHAR, time_value INTEGER, ext_json VARCHAR )");
                database.execSQL("CREATE TABLE item_action_v3 (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, target_type INTEGER NOT NULL, action VARCHAR NOT NULL, timestamp INTEGER NOT NULL, extra_data TEXT NOT NULL );");
            }

            if (oldVersion < 29) {
                database.execSQL("CREATE TABLE forum_item ( id INTEGER PRIMARY KEY, name VARCHAR NOT NULL, extra TEXT, fresh_time INTEGER NOT NULL DEFAULT 0 )");
            }

            if (oldVersion >= 31) {
                if (oldVersion < 36) {
                    try {
                        Logger.w("DBHelper", "upgrade v36");
                        database.execSQL("DROP TABLE IF EXISTS v30_article");
                        database.execSQL("CREATE TABLE v30_article ( _id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR NOT NULL, item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, tag VARCHAR, level INTEGER NOT NULL DEFAULT 0, behot_time INTEGER NOT NULL, share_url VARCHAR, digg_count INTEGER NOT NULL, bury_count INTEGER NOT NULL, repin_count INTEGER NOT NULL, comment_count INTEGER NOT NULL, user_digg INTEGER, user_bury INTEGER, user_repin INTEGER, user_repin_time INTEGER, source VARCHAR, title VARCHAR, url VARCHAR, city VARCHAR, keywords VARCHAR, publish_time INTEGER, hot INTEGER NOT NULL DEFAULT 0, tip INTEGER NOT NULL DEFAULT 0, has_image INTEGER NOT NULL DEFAULT 0, has_video INTEGER NOT NULL DEFAULT 0, abstract TEXT, image_list TEXT, comment_json TEXT, large_image_json TEXT, middle_image_json TEXT, group_type INTEGER NOT NULL DEFAULT 0, subject_label VARCHAR, item_version INTEGER NOT NULL DEFAULT 0, subject_group_id INTEGER NOT NULL DEFAULT 0, article_type INTEGER NOT NULL DEFAULT 0, article_sub_type INTEGER NOT NULL DEFAULT 0, article_url VARCHAR, article_alt_url VARCHAR, display_url VARCHAR, display_title VARCHAR, preload_web INTEGER NOT NULL DEFAULT 0, ban_comment INTEGER NOT NULL DEFAULT 0, natant_level INTEGER NOT NULL DEFAULT 0,group_flags INTEGER NOT NULL DEFAULT 0,tc_head_text TEXT, open_url VARCHAR, read_timestamp INTEGER, web_type_loadtime INTEGER NOT NULL DEFAULT 0, web_tc_loadtime INTEGER NOT NULL DEFAULT 0, stats_timestamp INTEGER, from_stream INTEGER NOT NULL DEFAULT 0, max_behot_time INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, user_dislike_time INTEGER NOT NULL DEFAULT 0, flag_dislike INTEGER NOT NULL DEFAULT 0, flag_repin INTEGER NOT NULL DEFAULT 0, flag_digg INTEGER NOT NULL DEFAULT 0, user_digg_time INTEGER NOT NULL DEFAULT 0, ext_json TEXT )");
                        database.execSQL("CREATE INDEX idx_stream ON v30_article (item_id, group_item_id)");
                        database.execSQL("CREATE INDEX idx_stream_rank ON v30_article (behot_time DESC)");
                        database.execSQL("CREATE INDEX idx_max_behot ON v30_article ( max_behot_time DESC)");
                    } catch (Exception v0) {
                        v0.printStackTrace();
                        Logger.w("DBHelper", "upgrade v36 exception " + oldVersion + " : " + v0);
                        return;
                    }
                }
            } else {
                Logger.w("DBHelper", "upgrade v30");
                database.execSQL("DROP TABLE IF EXISTS new_article");
                database.execSQL("CREATE TABLE v30_article ( _id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR NOT NULL, item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, tag VARCHAR, level INTEGER NOT NULL DEFAULT 0, behot_time INTEGER NOT NULL, share_url VARCHAR, digg_count INTEGER NOT NULL, bury_count INTEGER NOT NULL, repin_count INTEGER NOT NULL, comment_count INTEGER NOT NULL, user_digg INTEGER, user_bury INTEGER, user_repin INTEGER, user_repin_time INTEGER, source VARCHAR, title VARCHAR, url VARCHAR, city VARCHAR, keywords VARCHAR, publish_time INTEGER, hot INTEGER NOT NULL DEFAULT 0, tip INTEGER NOT NULL DEFAULT 0, has_image INTEGER NOT NULL DEFAULT 0, has_video INTEGER NOT NULL DEFAULT 0, abstract TEXT, image_list TEXT, comment_json TEXT, large_image_json TEXT, middle_image_json TEXT, group_type INTEGER NOT NULL DEFAULT 0, subject_label VARCHAR, item_version INTEGER NOT NULL DEFAULT 0, subject_group_id INTEGER NOT NULL DEFAULT 0, article_type INTEGER NOT NULL DEFAULT 0, article_sub_type INTEGER NOT NULL DEFAULT 0, article_url VARCHAR, article_alt_url VARCHAR, display_url VARCHAR, display_title VARCHAR, preload_web INTEGER NOT NULL DEFAULT 0, ban_comment INTEGER NOT NULL DEFAULT 0, natant_level INTEGER NOT NULL DEFAULT 0,group_flags INTEGER NOT NULL DEFAULT 0,tc_head_text TEXT, open_url VARCHAR, read_timestamp INTEGER, web_type_loadtime INTEGER NOT NULL DEFAULT 0, web_tc_loadtime INTEGER NOT NULL DEFAULT 0, stats_timestamp INTEGER, from_stream INTEGER NOT NULL DEFAULT 0, max_behot_time INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, user_dislike_time INTEGER NOT NULL DEFAULT 0, flag_dislike INTEGER NOT NULL DEFAULT 0, flag_repin INTEGER NOT NULL DEFAULT 0, flag_digg INTEGER NOT NULL DEFAULT 0, user_digg_time INTEGER NOT NULL DEFAULT 0, ext_json TEXT )");
                database.execSQL("CREATE INDEX idx_stream ON v30_article (item_id, group_item_id)");
                database.execSQL("CREATE INDEX idx_stream_rank ON v30_article (behot_time DESC)");
                database.execSQL("CREATE INDEX idx_max_behot ON v30_article ( max_behot_time DESC)");
                database.execSQL("DROP TABLE IF EXISTS new_detail");
                database.execSQL(" CREATE TABLE v30_detail ( _id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL DEFAULT 0, item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, content TEXT, timestamp INTEGER, expire_seconds INTEGER, cache_token VARCHAR, image_detail TEXT, thumb_image TEXT, ext_json TEXT, serial_data TEXT )");
                database.execSQL("DROP TABLE IF EXISTS v25_essay");
                database.execSQL("CREATE TABLE v30_essay ( _id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR NOT NULL, item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, tag VARCHAR, level INTEGER NOT NULL DEFAULT 0, behot_time INTEGER, share_url VARCHAR, digg_count INTEGER, bury_count INTEGER, repin_count INTEGER, comment_count INTEGER , user_digg INTEGER, user_bury INTEGER,user_repin INTEGER,user_repin_time INTEGER, content TEXT, create_time INTEGER, large_image TEXT, middle_image TEXT, god_comments TEXT, group_flags INTERGER NOT NULL DEFAULT 0, display_type INTERGER NOT NULL DEFAULT 0, stats_timestamp INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, max_behot_time INTEGER NOT NULL DEFAULT 0, read_timestamp INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE INDEX idx_essay ON v30_essay (item_id)");
                database.execSQL("CREATE INDEX idx_essay_time ON v30_essay (behot_time DESC)");
                database.execSQL("DROP TABLE IF EXISTS category_list");
                database.execSQL("CREATE TABLE v30_category_list (_id INTEGER PRIMARY KEY AUTOINCREMENT, category VARCHAR NOT NULL, cell_id VARCHAR NOT NULL, cell_type INTEGER NOT NULL DEFAULT -1, cell_data TEXT, ad_id INTEGER DEFAULT 0, cate_cursor INTEGER NOT NULL DEFAULT 0, cate_behot_time INTEGER NOT NULL DEFAULT 0 )");
                database.execSQL("CREATE INDEX idx_category ON v30_category_list (category, cell_id, cell_type)");
                database.execSQL("CREATE INDEX idx_category_rank ON v30_category_list (category, cate_behot_time DESC)");
                database.execSQL("DROP TABLE IF EXISTS item_action");
                database.execSQL("CREATE TABLE item_action (item_id INTEGER NOT NULL, group_item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, action INTEGER NOT NULL, timestamp INTEGER NOT NULL,  PRIMARY KEY (item_id, group_item_id, action) );");
                database.execSQL("CREATE INDEX idx_action_time ON item_action (timestamp)");
                database.execSQL("DROP TABLE IF EXISTS item_action_v3");
                database.execSQL("CREATE TABLE item_action_v3 (_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, item_id INTEGER NOT NULL DEFAULT 0, aggr_type INTEGER NOT NULL DEFAULT 0, target_type INTEGER NOT NULL, action VARCHAR NOT NULL, timestamp INTEGER NOT NULL, extra_data TEXT NOT NULL );");
                if (oldVersion >= 15) {
                    try {
                        database.delete("article_category", null, null);
                    } catch (Exception e) {
                        Logger.w("DBHelper", "upgrade v30 exception " + oldVersion + " : " + e);
                    }
                }
            }

            if (oldVersion >= 31 && oldVersion < 32) {
                try {
                    database.execSQL("ALTER TABLE v30_detail ADD COLUMN ext_json TEXT");
                } catch (Exception v0) {
                    Logger.e("DBHelper", "onUpgrade " + oldVersion + " to " + newVersion + " exception: " + v0);
                    return;
                }
            }

            if (oldVersion >= 23 && oldVersion < 33) {
                try {
                    database.execSQL("alter table impression ADD COLUMN extra TEXT");
                } catch (Exception exception) {
                    try {
                        Logger.throwExceptionInDebug(exception);
                        database.execSQL("drop table if exists impression");
                        database.execSQL("CREATE TABLE IF NOT EXISTS impression (key_name VARCHAR, list_type INTEGER NOT NULL DEFAULT 0, session_id INTEGER NOT NULL DEFAULT 0, impression TEXT, extra TEXT )");
                    } catch (Exception ex) {
                        Logger.e("DBHelper", "onUpgrade " + oldVersion + " to " + newVersion + " exception: " + ex);
                        return;
                    }
                }
            }

            try {
                if (oldVersion < 35) {
                    database.execSQL("CREATE TABLE IF NOT EXISTS net_request_queue ( key VARCHAR NOT NULL, type INTEGER NOT NULL DEFAULT 0, url VARCHAR, request_method INTEGER, entity_json VARCHAR,time INTEGER NOT NULL,retry_count INTEGER,extra VARCHAR , PRIMARY KEY (type,key,time ) )");


                }
                if (oldVersion < 37) {
                    database.execSQL("CREATE TABLE IF NOT EXISTS subscribed_video_pgc_user ( id INTEGER PRIMARK KEY, avatarUrl VARCHAR, modify_time INTEGER DEFAULT 0, description VARCHAR, extraJson VARCHAR, name VARCHAR, scheme VARCHAR, user_verified INTEGER )");
                    database.delete("v30_detail", null, null);
                }

                if (oldVersion < 38) {
                    database.execSQL("CREATE TABLE v38_post ( _id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL, item_id INTEGER NOT NULL, key VARCHAR NOT NULL, title VARCHAR, content TEXT, schema TEXT, inner_ui_flag INTEGER, behot_time INTEGER, share_url VARCHAR, digg_count INTEGER, bury_count INTEGER, repin_count INTEGER, comment_count INTEGER, user_digg INTEGER, user_bury INTEGER, user_repin INTEGER, user_repin_time INTEGER, large_image_list TEXT, thumb_image_list TEXT, forum TEXT, user TEXT, friend_digg_list TEXT, comments TEXT, group_json TEXT, position_json TEXT, stats_timestamp INTEGER NOT NULL DEFAULT 0, user_dislike INTEGER NOT NULL DEFAULT 0, read_timestamp INTEGER NOT NULL DEFAULT 0, score REAL NOT NULL DEFAULT 0.0 )");
                    database.execSQL(" CREATE TABLE v38_category_meta ( _id INTEGER PRIMARY KEY AUTOINCREMENT, concern_id INTEGER, category_name VARCHAR, concern_info TEXT, show_et_status INTEGER, post_content_hint TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
                }

                if (oldVersion < 39) {
                    database.execSQL("CREATE INDEX idx_post_id ON v38_post (id)");
                    database.execSQL("CREATE INDEX idx_post_item_id ON v38_post (item_id)");
                    database.execSQL("CREATE INDEX idx_category_meta_concern_id ON v38_category_meta (concern_id)");
                    database.execSQL("CREATE INDEX idx_category_meta_category_name ON v38_category_meta (category_name)");
                }

                if (oldVersion > 31 && oldVersion < 40) {
                    database.execSQL("ALTER TABLE v30_category_list ADD COLUMN cate_cursor INTEGER NOT NULL DEFAULT 0");
                }

                if (oldVersion > 37 && oldVersion < 41) {
                    database.execSQL("ALTER TABLE v38_category_meta ADD COLUMN post_content_hint TEXT");
                }

                if (oldVersion < 42) {
                    database.execSQL("DROP TABLE IF EXISTS v38_category_meta");
                    database.execSQL(" CREATE TABLE v38_category_meta ( _id INTEGER PRIMARY KEY AUTOINCREMENT, concern_id INTEGER, category_name VARCHAR, concern_info TEXT, show_et_status INTEGER, post_content_hint TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
                    database.execSQL("CREATE INDEX idx_category_meta_concern_id ON v38_category_meta (concern_id)");
                    database.execSQL("CREATE INDEX idx_category_meta_category_name ON v38_category_meta (category_name)");
                }

                if (oldVersion < 43) {
                    database.execSQL("ALTER TABLE v30_detail ADD COLUMN serial_data TEXT");
                }

                if (oldVersion > 38 && oldVersion < 44) {
                    database.execSQL("ALTER TABLE v38_post ADD COLUMN score REAL NOT NULL DEFAULT 0.0");
                }

                if (oldVersion >= 22 && oldVersion < 45) {
                    database.execSQL("DROP TABLE IF EXISTS update_list_meta");
                    database.execSQL("DROP TABLE IF EXISTS update_item");
                    database.execSQL("CREATE TABLE update_list_meta ( user_id INTEGER PRIMARY KEY, top_cursor INTEGER NOT NULL, bottom_cursor INTEGER NOT NULL, refresh_time INTEGER NOT NULL )");
                    database.execSQL("CREATE TABLE update_item ( user_id INTEGER NOT NULL DEFAULT 0, update_id INTEGER NOT NULL, cursor INTEGER NOT NULL, create_time INTEGER NOT NULL, flags INTEGER NOT NULL, reason VARCHAR, item_json TEXT, refresh_time INTEGER NOT NULL DEFAULT 0 )");
                }

                if (oldVersion >= 46) {
                    return;
                }
                database.execSQL("ALTER TABLE v27_entry ADD COLUMN user_id INTEGER NOT NULL DEFAULT 0");
            } catch (Exception e) {
                Logger.e("DBHelper", "onUpgrade " + oldVersion + " to " + newVersion + " exception: " + e);
            }
        }
    }

    private String A;
    private long B;
    private static String[] update_item_colums = new String[]{"user_id", "update_id", "cursor", "create_time", "flags", "reason", "item_json", "refresh_time"};
    private static String[] c = new String[]{"id", "name", "extra", "fresh_time"};
    private static String[] d = new String[]{"e_int_value", "e_str_value", "e_time_value", "e_ext_json"};
    private static String[] e = new String[]{"id", "name", "description", "icon", "type", "tip_new", "subscribe_count", "is_subscribe", "wap_url", "group_id", "ext_json", "user_id"};
    private static String ENTRY_GROUP_JOINED_COLUMNS = TextUtils.join(",", e);
    private static String SELECT_ENTRY_GROUP_SQL = "SELECT " + ENTRY_GROUP_JOINED_COLUMNS + " FROM v27_entry_group JOIN v27_entry  ON v27_entry_group.e_group_id = ? AND v27_entry_group.e_entry_id = v27_entry.id  ORDER BY v27_entry_group.e_list_order";
    private static String h = "SELECT " + ENTRY_GROUP_JOINED_COLUMNS + "," + TextUtils.join(",", d) + " FROM v27_entry_group JOIN v27_entry  ON v27_entry_group.e_group_id = -1 AND v27_entry_group.e_entry_id = v27_entry.id ORDER BY v27_entry_group.e_list_order";
    private static String[] i = new String[]{"name", "int_value", "str_value", "time_value", "ext_json"};
    private static String[] article_category_colums = new String[]{"category", "last_refresh_time", "last_loadmore_time", "top_time", "bottom_time"};
    private static String[] v30_article_colums = new String[]{"item_id", "group_item_id",
            "aggr_type", "tag", "level", "behot_time", "share_url", "digg_count", "bury_count",
            "repin_count", "comment_count", "user_digg", "user_bury", "user_repin",
            "user_repin_time", "source", "title", "url", "city", "keywords", "publish_time", "hot",
            "tip", "has_image", "has_video", "abstract", "image_list", "comment_json",
            "large_image_json", "middle_image_json", "group_type", "subject_label", "item_version",
            "subject_group_id", "article_type", "article_sub_type", "article_url",
            "article_alt_url", "display_url", "display_title", "preload_web", "ban_comment",
            "natant_level", "group_flags", "tc_head_text", "open_url", "read_timestamp",
            "web_type_loadtime", "web_tc_loadtime", "stats_timestamp", "user_dislike", "ext_json"};
    private static String[] l = new String[]{"item_id", "tag", "level", "behot_time", "share_url", "digg_count", "bury_count", "repin_count", "comment_count", "user_digg", "user_bury", "user_repin", "user_repin_time", "content", "create_time", "large_image", "middle_image", "god_comments", "group_flags", "display_type", "stats_timestamp", "user_dislike", "read_timestamp"};
    private static String[] m = new String[]{"id", "title", "content", "schema", "inner_ui_flag", "behot_time", "share_url", "digg_count", "bury_count", "repin_count", "comment_count", "user_digg", "user_bury", "user_repin", "user_repin_time", "large_image_list", "thumb_image_list", "forum", "user", "friend_digg_list", "comments", "group_json", "position_json", "stats_timestamp", "user_dislike", "read_timestamp", "score"};
    private static String[] n = new String[]{"_id", "concern_id", "category_name", "concern_info", "show_et_status", "post_content_hint", "refresh_time"};
    private static String ARTICLE_JOINED_COLUMNS = TextUtils.join(",", v30_article_colums);
    private static String ARTICLE_RAW_QUERY_SQL = "SELECT " + ARTICLE_JOINED_COLUMNS + ",cate_behot_time,cell_data, ad_id, cate_cursor FROM v30_category_list JOIN v30_article ON v30_category_list.category = ?  AND v30_category_list.cate_behot_time <= ?  AND v30_category_list.cate_behot_time >= ?  AND v30_category_list.cell_type = 0  AND v30_category_list.cell_id = v30_article.key AND v30_article.user_dislike = 0  ORDER BY v30_category_list.cate_behot_time DESC LIMIT ?";
    private static String q = TextUtils.join(",", l);
    private static String r = "SELECT " + q + ",cate_behot_time, cell_data, cate_cursor FROM v30_category_list JOIN v30_essay ON v30_category_list.category = ?  AND v30_category_list.cate_behot_time <= ?  AND v30_category_list.cate_behot_time >= ?  AND v30_category_list.cell_type = 3  AND v30_category_list.cell_id = v30_essay.key AND v30_essay.user_dislike = 0  ORDER BY v30_category_list.cate_behot_time DESC LIMIT ?";
    private static String s = TextUtils.join(",", m);
    private static String t = "SELECT " + s + ",cate_behot_time, cell_data, cate_cursor FROM v30_category_list JOIN v38_post ON v30_category_list.category = ?  AND v30_category_list.cate_behot_time <= ?  AND v30_category_list.cate_behot_time >= ?  AND v30_category_list.cell_type =  32 AND v30_category_list.cell_id = v38_post.key AND v38_post.user_dislike = 0  ORDER BY v30_category_list.cate_behot_time DESC LIMIT ?";
    private static String u = TextUtils.join(",", n);
    private static String v = TextUtils.join(",", c);
    private static final Object mLock = new Object();
    private static DBHelper ins;
    private long lastShrinkTs;
    private SSDBHelper.a$a z;

    static {
        new StringBuilder("SELECT ").append(u).append(" FROM v38_category_meta ORDER BY v38_category_meta.refresh_time DESC ");
        new StringBuilder("SELECT ").append(v).append(" FROM forum_item ORDER BY forum_item.fresh_time DESC ");
    }

    private DBHelper(Context context) {
        super(context);
        this.lastShrinkTs = 0;
        this.z = new SSDBHelper.a$a();
        this.B = 0;
    }

    public static DBHelper getInstance(Context context) {
        synchronized (mLock) {
            if (ins == null) {
                ins = new DBHelper(context.getApplicationContext());
            }
        }
        return ins;
    }

    public final void a(int cellType, String cellId, String category) {
        if ((CellRef.isValidCellType(cellType))
                && !android.support.design.a.isTextEmpty(cellId)
                && !android.support.design.a.isTextEmpty(category)) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(111));
            contentValues.put("cell_type", Integer.valueOf(cellType));
            contentValues.put("cell_id", cellId);
            contentValues.put("category", category);
            this.asyncUpdate(contentValues);
        }
    }

    public final void a(Article article) {
        if (article != null && article.groupId > 0) {
            ContentValues v0 = article2ContentValues(article, true, false);
            v0.put("ss_op_key", Integer.valueOf(1));
            v0.put("op_item_type", Integer.valueOf(ItemType.ARTICLE.getValue()));
            v0.put("item_id", Long.valueOf(article.groupId));
            v0.put("group_item_id", Long.valueOf(article.itemId));
            this.asyncUpdate(v0);
        }
    }

    public final ArticleDetail queryArticleDetail(AbsArticle absArticle, boolean fillArticle) {
        synchronized (this) {
            if (absArticle != null) {
                String[] selectionArgs;
                String selection;
                String limit;
                if (absArticle.opItemType == ItemType.ARTICLE && absArticle.groupId > 0L) {
                    if (this.isSQLiteDatabaseAvailable()) {
                        limit = "1";
                        selection = "item_id =?  AND group_item_id = ?";
                        selectionArgs = new String[]{String.valueOf(absArticle.groupId), String.valueOf(absArticle.itemId)};
                    } else {
                        return null;
                    }
                } else {
                    return null;
                }

                try {
                    ArticleDetail articleDetail = new ArticleDetail();
                    articleDetail.itemId = absArticle.groupId;
                    Cursor cursor;
                    if (fillArticle) {
                        cursor = this.mSQLiteDatabase.query("v30_article",
                                v30_article_colums,
                                selection,
                                selectionArgs,
                                null,
                                null,
                                null,
                                limit);
                        Article article;
                        if (cursor.moveToNext()) {
                            article = parseArticleFromCursor(cursor);
                        } else {
                            article = null;
                        }
                        if (article != null) {
                            articleDetail.article = article;
                            closeQuietly(cursor);
                        } else {
                            closeQuietly(cursor);
                            return null;
                        }
                    }
                    cursor = this.mSQLiteDatabase.query("v30_detail",
                            new String[]{"content", "cache_token", "timestamp", "expire_seconds", "image_detail", "thumb_image", "ext_json", "serial_data"},
                            "group_id =?  AND item_id = ?",
                            selectionArgs,
                            null,
                            null,
                            null,
                            limit);
                    if (!cursor.moveToNext()) {
                        return articleDetail;
                    }
                    articleDetail.content = android.support.design.a.getColumnValue(cursor, "content");
                    articleDetail.cacheToken = android.support.design.a.getColumnValue(cursor, "cache_token");
                    articleDetail.timestamp = android.support.design.a.b(cursor, "timestamp");
                    articleDetail.expireSeconds = android.support.design.a.b(cursor, "expire_seconds");
                    String imageDetail = android.support.design.a.getColumnValue(cursor, "image_detail");
                    if (android.support.design.a.isTextEmpty(imageDetail)) {
                        articleDetail.imageDetail = ImageInfo.parseImageList(new JSONArray(imageDetail), false);
                        String thumbImage = android.support.design.a.getColumnValue(cursor, "thumb_image");
                        if (!android.support.design.a.isTextEmpty(thumbImage)) {
                            ImageInfo.parseImageList(new JSONArray(thumbImage), false);
                        }
                        articleDetail.extJson = android.support.design.a.getColumnValue(cursor, "ext_json");
                        JSONObject mediaJO;
                        if (!android.support.design.a.isTextEmpty(articleDetail.extJson)) {
                            JSONObject extJSONObject = new JSONObject(articleDetail.extJson);
                            articleDetail.pictureListItem = extJSONObject.optString("picture_list_item");
                            thumbImage = articleDetail.pictureListItem;
                            if (!android.support.design.a.isTextEmpty(thumbImage)) {
                                articleDetail.parseGalleryImageInfoList(new JSONArray(thumbImage));
                            }
                            articleDetail.h5Extra = extJSONObject.optString("h5_extra");
                            JSONObject h5ExtraJO = null;
                            if (!android.support.design.a.isTextEmpty(articleDetail.h5Extra)) {
                                h5ExtraJO = new JSONObject(articleDetail.h5Extra);
                                articleDetail.isOriginal = h5ExtraJO.optBoolean("is_original");
                            }
                            articleDetail.mediaUserId = extJSONObject.optLong("media_user_id", 0);
                            articleDetail.mediaInfo = extJSONObject.optString("media_info");
                            if (!android.support.design.a.isTextEmpty(articleDetail.mediaInfo)) {
                                mediaJO = new JSONObject(articleDetail.mediaInfo);
                            } else {
                                if (h5ExtraJO != null) {
                                    mediaJO = h5ExtraJO.optJSONObject("media");
                                } else {
                                    mediaJO = null;
                                }
                            }
                            if (mediaJO != null) {
                                articleDetail.mediaId = mediaJO.optLong("media_id");
                                articleDetail.name = mediaJO.optString("name");
                                articleDetail.userVerified = mediaJO.optBoolean("user_verified");
                                articleDetail.avatarUrl = mediaJO.optString("avatar_url");
                                articleDetail.canBePraised = AbsApiThread.optBoolean(mediaJO, "can_be_praised", false);
                                articleDetail.praiseData = PraiseData.fromJSONObject(mediaJO);
                            }

                            if (articleDetail.praiseData == null && h5ExtraJO != null) {
                                mediaJO = h5ExtraJO.optJSONObject("media");
                                if (mediaJO != null) {
                                    articleDetail.canBePraised = AbsApiThread.optBoolean(mediaJO, "can_be_praised", false);
                                    articleDetail.praiseData = PraiseData.fromJSONObject(mediaJO);
                                }
                            }
                            articleDetail.isWenda = extJSONObject.optInt("is_wenda") > 0;
                            articleDetail.etag = extJSONObject.optString("wenda_etag");
                            articleDetail.wendaExtra = extJSONObject.optString("wenda_extra");
                            articleDetail.parseWendaExtra(articleDetail.wendaExtra);
                        }
                        articleDetail.novelDataJson = android.support.design.a.getColumnValue(cursor, "serial_data");
                        if (!TextUtils.isEmpty(articleDetail.novelDataJson)) {
                            mediaJO = new JSONObject(articleDetail.novelDataJson);
                            articleDetail.novelData = new ArticleDetail.NovelData();
                            articleDetail.novelData.initWithJSONObject(mediaJO);
                        }
                        return articleDetail;
                    }
                } catch (Exception e) {
                }
            }
        }
        return null;
    }

    public final List a(long arg12) {
        Cursor v0_3;
        Cursor v1 = null;
        ArrayList v10;
        String[] v4;
        String v3;
        List v0;
        List v9 = null;
        synchronized (this) {
            if (arg12 <= 0) {
                v0 = v9;
                return v0;
            }

            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    v0 = v9;
                    return v0;
                }
                v3 = "item_id =?";
                v4 = new String[]{String.valueOf(arg12)};
                v10 = new ArrayList();
                v1 = this.mSQLiteDatabase.query("v30_article", v30_article_colums, v3, v4, null, null, null, null);
                while (v1.moveToNext()) {
                    ((List) v10).add(parseArticleFromCursor(v1));
                }
                v1.close();

                ArrayList v0_4 = v10;
                return v0_4;
            } catch (Exception v0_2) {
                Logger.w("DBHelper", "get base article exception: " + v0_2);
            } finally {
                closeQuietly(v1);
            }
        }
        return null;
    }

    public final Article a(AbsArticle arg11) {
        Cursor v1 = null;
        String[] v4;
        String v3;
        String v8;
        Article v0_1;
        Article v9 = null;
        synchronized (this) {
            if (arg11 != null) {
                try {
                    if (arg11.opItemType == ItemType.ARTICLE && arg11.groupId > 0) {
                        if (!this.isSQLiteDatabaseAvailable()) {
                            v0_1 = v9;
                            return v0_1;
                        } else {
                            try {
                                v8 = "1";
                                v3 = "item_id =?  AND group_item_id = ?";
                                v4 = new String[]{String.valueOf(arg11.groupId), String.valueOf(arg11.itemId)};
                                v1 = this.mSQLiteDatabase.query("v30_article", v30_article_colums, v3, v4, null, null, null, v8);
                                if (v1.moveToNext()) {
                                    v0_1 = parseArticleFromCursor(v1);
                                } else {
                                    v0_1 = v9;
                                }
                                return v0_1;
                            } catch (Exception e) {
                                Logger.w("DBHelper", "get base article exception: " + e);
                            } finally {
                                closeQuietly(v1);
                            }
                        }
                    }
                    return v9;
                } catch (Throwable v0) {
                }
            }
        }
        return v9;
    }

    private static ContentValues article2ContentValues(Article article, boolean arg9, boolean isFromStream) {
        ContentValues contentValues = new ContentValues();
        if (!arg9) {
            contentValues.put("item_id", Long.valueOf(article.groupId));
            contentValues.put("key", article.getItemKey());
            contentValues.put("group_item_id", Long.valueOf(article.itemId));
            contentValues.put("behot_time", Long.valueOf(article.behotTime));
        }

        contentValues.put("aggr_type", Integer.valueOf(article.aggrType));
        if (isFromStream) {
            contentValues.put("from_stream", Integer.valueOf(1));
        }

        contentValues.put("max_behot_time", Long.valueOf(article.behotTime));
        contentValues.put("tag", article.tag);
        contentValues.put("level", Integer.valueOf(article.level));
        contentValues.put("share_url", article.shareUrl);
        contentValues.put("digg_count", Integer.valueOf(article.diggCount));
        contentValues.put("bury_count", Integer.valueOf(article.buryCount));
        contentValues.put("repin_count", Integer.valueOf(article.repinCount));
        contentValues.put("comment_count", Integer.valueOf(article.commentCount));
        contentValues.put("user_digg", Integer.valueOf(article.userDigg ? 1 : 0));
        contentValues.put("user_bury", Integer.valueOf(article.userBury ? 1 : 0));
        contentValues.put("user_repin", Boolean.valueOf(article.userRepin));
        contentValues.put("user_repin_time", Long.valueOf(article.userRepinTime));
        contentValues.put("source", article.source);
        contentValues.put("title", article.title);
        contentValues.put("url", article.url);
        contentValues.put("city", article.city);
        contentValues.put("keywords", article.keywords);
        contentValues.put("publish_time", Long.valueOf(article.publishTime));
        contentValues.put("hot", Integer.valueOf(article.hot));
        contentValues.put("has_image", Integer.valueOf(article.hasImage ? 1 : 0));
        contentValues.put("has_video", Integer.valueOf(article.hasVideo ? 1 : 0));
        contentValues.put("abstract", article._abstract);
        contentValues.put("image_list", article.imageList1);
        contentValues.put("comment_json", article.commentJson);
        contentValues.put("large_image_json", article.largeImageJson);
        contentValues.put("middle_image_json", article.middleImageJson);
        contentValues.put("group_type", Integer.valueOf(article.groupType));
        contentValues.put("subject_label", article.subjectLabel);
        contentValues.put("item_version", Long.valueOf(article.itemVersion));
        contentValues.put("subject_group_id", Long.valueOf(article.subjectGroupId));
        contentValues.put("article_type", Integer.valueOf(article.articleType));
        contentValues.put("article_sub_type", Integer.valueOf(article.articleSubType));
        contentValues.put("article_url", article.articleUrl);
        contentValues.put("article_alt_url", article.articleAltUrl);
        contentValues.put("display_url", article.displayUrl);
        contentValues.put("display_title", article.displayTitle);
        contentValues.put("preload_web", Integer.valueOf(article.preloadWeb));
        contentValues.put("ban_comment", Integer.valueOf(article.mBanComment ? 1 : 0));
        contentValues.put("natant_level", Integer.valueOf(article.natantLevel));
        contentValues.put("group_flags", Integer.valueOf(article.groupFlags));
        contentValues.put("tc_head_text", article.tcHeadText);
        contentValues.put("open_url", article.openUrl);
        contentValues.put("stats_timestamp", Long.valueOf(article.statsTimestamp));
        JSONObject extJson = new JSONObject();
        try {
            extJson.put("video_id", article.videoId);
            extJson.put("video_duration", article.videoDuration);
            extJson.put("ad_video_click_track_urls", article.adVideoClickTrackUrlsJson);
            extJson.put("impression_timestamp", article.impressionTimestamp);
            extJson.put("media_name", article.mediaName);
            extJson.put("reason", article.reason);
            extJson.put("user_like", article.userLike);
            extJson.put("like_count", article.likeCount);
            extJson.put("comments", article.commentsJson);
            extJson.put("zzcomment", article.zzcommentJson);
            extJson.put("media_info", article.mediaInfoJson);
            extJson.put("user_info", article.userInfoJson);
            extJson.put("gallary_image_count", article.gallaryImageCount);
            extJson.put("gallary_flag", article.gallaryFlag);
            if (!android.support.design.a.isTextEmpty(article.videoDetailInfo)) {
                extJson.put("video_detail_info", article.videoDetailInfo);
            }

            extJson.put("entity_style", article.entityStyle);
            extJson.put("entity_id", article.entityId);
            extJson.put("entity_word", article.entityWord);
            extJson.put("entity_text", article.entityText);
            extJson.put("entity_mark", article.entityMarkJson);
            extJson.put("entity_followed", article.entityFollowed);
            extJson.put("entity_scheme", article.entityScheme);
            extJson.put("concern_id", article.concernId);
            extJson.put("is_original", article.isOriginal);
            extJson.put("tiny_toutiao_url", article.tinyToutiaoUrl);
            extJson.put("wap_headers", article.wapHeaders);
            extJson.put("ignore_web_transform", article.ignoreWebTransform ? 1 : 0);
            extJson.put("media_user_id", article.mediaUserId);
            article.extJson = extJson.toString();
        } catch (JSONException v0_2) {
            Logger.d("Article", "exception in appendExtraData : " + v0_2.toString());
        }

        contentValues.put("ext_json", article.extJson);
        return contentValues;
    }

    private static ContentValues entryItem2ContentValues(boolean arg8, EntryItem entryItem, boolean arg10) {
        ContentValues contentValues = new ContentValues();
        if (!arg8) {
            contentValues.put("id", Long.valueOf(entryItem.mId));
        }

        contentValues.put("type", Integer.valueOf(entryItem.mType));
        contentValues.put("name", entryItem.mName);
        contentValues.put("description", entryItem.mDescription);
        contentValues.put("icon", entryItem.mIconUrl);
        contentValues.put("subscribe_count", Integer.valueOf(entryItem.mSubscribeCount));
        contentValues.put("tip_new", Integer.valueOf(entryItem.mShowNewTip ? 1 : 0));
        contentValues.put("wap_url", entryItem.mWapUrl);
        contentValues.put("group_id", Long.valueOf(entryItem.mGroupId));
        if (entryItem.mUserId != 0) {
            contentValues.put("user_id", Long.valueOf(entryItem.mUserId));
        }
        contentValues.put("is_subscribe", Integer.valueOf(arg10 ? 1 : 0));
        return contentValues;
    }

    private List<CellRef> queryEmbeddedCell(String category, long cateBehotTimeMin, long cateBehotTimeMax, int limit) {
        Cursor cursor = null;
        ArrayList result = new ArrayList();
        if (cateBehotTimeMin <= 0) {
            cateBehotTimeMin = 1099511627776L;
        }

        if (!android.support.design.a.isTextEmpty(category) && (cateBehotTimeMin <= 0 || cateBehotTimeMin > cateBehotTimeMax)) {
            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    return result;
                }
                String[] columns = new String[4];
                columns[0] = "cate_behot_time";
                columns[1] = "cell_type";
                columns[2] = "cell_id";
                columns[3] = "cell_data";
                String selection = "category=? AND cell_type IN (" + CellRef.VALID_CELL_TYPES_STR + ")  AND cate_behot_time <= ?  AND cate_behot_time >= ? ";
                String[] selectionArgs = new String[]{category, String.valueOf(cateBehotTimeMin), String.valueOf(cateBehotTimeMax)};
                String sortBy = "cate_behot_time DESC";
                String limitStr = limit > 0 ? String.valueOf(limit) : "100";
                cursor = this.mSQLiteDatabase.query("v30_category_list", columns, selection, selectionArgs, null, null, sortBy, limitStr);
                while (cursor.moveToNext()) {
                    long cateBehotTime = cursor.getLong(0);
                    int cellType = cursor.getInt(1);
                    if (!CellRef.isValidCellType(cellType)) {
                        continue;
                    }

                    if (android.support.design.a.isTextEmpty(cursor.getString(2))) {
                        continue;
                    }

                    String cellData = cursor.getString(3);
                    if (android.support.design.a.isTextEmpty(cellData)) {
                        continue;
                    }

                    CellRef cellRef = new CellRef(cellType, category, cateBehotTime);
                    cellRef.appendExtraData = cellData;
                    JSONObject jo = new JSONObject(cellData);
                    if (!CellRef.extractOther(cellRef, jo)) {
                        continue;
                    }

                    CellRef.extractFromJO(cellRef, jo, false);
                    result.add(cellRef);
                }
                return result;
            } catch (Exception e) {
                Logger.w("DBHelper", "query embeded cell exception: " + e);
            } finally {
                closeQuietly(cursor);
            }
        }
        return result;
    }

    public final boolean isSQLiteDatabaseAvailable() {
        boolean available = super.isSQLiteDatabaseAvailable();
        if (available) {
            long now = System.currentTimeMillis();
            if (now - this.lastShrinkTs > 12 * 60 * 60 * 1000L && Looper.myLooper() != Looper.getMainLooper()) {
                this.lastShrinkTs = now;
                if (this.shouldShrink()) {
                    this.cleanV30Article();
                    this.cleanCategory();
                    this.cleanV30Essay();
                    this.cleanSearchWord();
                    this.shrinkCategoryMeta(now);
                    Logger.d("DBHelper", "shrink cache time: " + (System.currentTimeMillis() - now));
                } else {
                    Logger.d("DBHelper", "Skip force shrink. Use time: " + (System.currentTimeMillis() - now));
                }
            }
        }

        return available;
    }

    private List queryCategory(String arg9, long arg10, long arg12, int arg14, ItemType arg15) {
        CellRef cellRef;
        int v4;
        Cursor cursor = null;
        String sql;
        ArrayList v0 = new ArrayList();
        if (!this.isSQLiteDatabaseAvailable()) {
            return v0;
        }

        if (android.support.design.a.isTextEmpty(arg9)) {
            return v0;
        }

        int v1 = 4;
        try {
            String[] selectionArgs = new String[v1];
            selectionArgs[0] = arg9;
            selectionArgs[1] = "0";
            selectionArgs[2] = "0";
            selectionArgs[3] = "100";
            if (arg15 == ItemType.ARTICLE) {
                sql = ARTICLE_RAW_QUERY_SQL;
            } else if (arg15 == ItemType.ESSAY) {
                sql = r;
            } else if (arg15 == ItemType.TOPIC) {
                sql = t;
            } else {
                return v0;
            }
            selectionArgs[1] = arg10 > 0 ? String.valueOf(arg10) : "1099511627776";
            if (arg12 > 0) {
                selectionArgs[2] = String.valueOf(arg12);
            }
            if (arg14 > 0) {
                selectionArgs[3] = String.valueOf(arg14);
            }
            cursor = this.mSQLiteDatabase.rawQuery(sql, selectionArgs);
            v4 = cursor.getColumnIndex("cate_cursor");
            while (true) {
                if (!cursor.moveToNext()) {
                    return v0;
                }
                if (arg15 == ItemType.ARTICLE) {
                    Article article = parseArticleFromCursor(cursor);
                    cellRef = new CellRef(arg9, article.behotTime, article);
                    cellRef.cateBehotTime = cursor.getLong(52);
                    cellRef.appendExtraData = cursor.getString(53);
                    cellRef.adId = cursor.getLong(54);
                    if (!android.support.design.a.isTextEmpty(cellRef.appendExtraData)) {
                        JSONObject jsonObject = new JSONObject(cellRef.appendExtraData);
                        CellRef.extractFromJO(cellRef, jsonObject, false);
                        String adData = jsonObject.optString("ad_data");
                        if (!android.support.design.a.isTextEmpty(adData)) {
                            CellRef.extractAd(cellRef, new JSONObject(adData), false);
                        }
                    }
                } else {
                    cellRef = null;
                }

                if (cellRef == null) {
                    continue;
                }
                if (v4 >= 0) {
                    cellRef.cateCursor = cursor.getLong(v4);
                }
                v0.add(cellRef);
            }
        } catch (Exception exception) {
            Logger.w("DBHelper", "querycategory exception " + exception);
        } finally {
            closeQuietly(cursor);
            return v0;
        }
    }

    private void updateCategoryList(CellRef cellRef, boolean arg8) {
        if (cellRef != null
                && !android.support.design.a.isTextEmpty(cellRef.cellId)
                && cellRef.cateBehotTime > 0
                && !android.support.design.a.isTextEmpty(cellRef.appendExtraData)
                && (CellRef.isValidCellType(cellRef.cellType))) {
            String[] whereArgs = new String[3];
            whereArgs[0] = "0";
            whereArgs[1] = cellRef.category;
            whereArgs[2] = "0";
            whereArgs[0] = cellRef.cellId;
            whereArgs[2] = String.valueOf(cellRef.cellType);
            ContentValues contentValues = new ContentValues();
            contentValues.put("cate_behot_time", Long.valueOf(cellRef.cateBehotTime));
            contentValues.put("cate_cursor", Long.valueOf(cellRef.cateCursor));
            contentValues.put("cell_data", cellRef.appendExtraData);
            contentValues.put("ad_id", Long.valueOf(cellRef.getAdId()));
            if (this.mSQLiteDatabase.update("v30_category_list", contentValues, "cell_id =?  AND category =?  AND cell_type =?", whereArgs) <= 0 && !arg8) {
                contentValues.put("category", cellRef.category);
                contentValues.put("cell_type", Integer.valueOf(cellRef.cellType));
                contentValues.put("cell_id", cellRef.cellId);
                this.mSQLiteDatabase.insert("v30_category_list", null, contentValues);
            }
        }
    }

    private void updateDetail(AbsArticle absArticle, String cacheToken, long timestamp, long expireSeconds) {
        synchronized (this) {
            try {
                if (absArticle.opItemType != ItemType.ARTICLE) {
                    return;
                }
                if (absArticle.groupId <= 0) {
                    return;
                }
                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }
                String[] whereArgs = new String[2];
                whereArgs[0] = String.valueOf(absArticle.groupId);
                whereArgs[1] = String.valueOf(absArticle.itemId);
                ContentValues contentValues = new ContentValues();
                if (!android.support.design.a.isTextEmpty(cacheToken)) {
                    contentValues.put("cache_token", cacheToken);
                }
                contentValues.put("timestamp", Long.valueOf(timestamp));
                contentValues.put("expire_seconds", Long.valueOf(expireSeconds));
                this.mSQLiteDatabase.update("v30_detail", contentValues, "group_id =?  AND item_id = ?", whereArgs);
            } catch (Exception e) {
                Logger.w("DBHelper", "update detail exception: " + e);
            }
        }
    }

    private void deleteOrCancelOldStickDatas(List<CellRef> cellRefList, int actionToLastStick, String category) {
        Logger.d("tag_stick", "start delete/cancel old stick datas");
        try {
            this.mSQLiteDatabase.beginTransaction();
            Iterator<CellRef> iterator = cellRefList.iterator();
            String[] whereArgs = new String[3];
            while (true) {
                if (!iterator.hasNext()) {
                    this.mSQLiteDatabase.setTransactionSuccessful();
                    Logger.d("tag_stick", "all delete or cancel actions, success");
                    return;
                }

                CellRef cellRef = iterator.next();
                String cellId;
                switch (cellRef.cellType) {
                    case 0: {
                        cellId = cellRef.article != null ? cellRef.article.getItemKey() : null;
                        break;
                    }
                    default: {
                        cellId = CellRef.isValidCellType(cellRef.cellType) ? cellRef.cellId : null;
                        break;
                    }
                }

                if (android.support.design.a.isTextEmpty(cellId)) {
                    continue;
                }
                whereArgs[0] = cellId;
                whereArgs[1] = category;
                whereArgs[2] = String.valueOf(cellRef.cellType);
                if (actionToLastStick == 1) {
                    int id = this.mSQLiteDatabase.delete("v30_category_list", "cell_id =?  AND category =?  AND cell_type =?", whereArgs);
                    StringBuilder stringBuilder = new StringBuilder("delete last stick :").append(cellId).append(";result:");
                    Logger.d("tag_stick", stringBuilder.append(id > 0).toString());
                    continue;
                }

                CellRef.appendExtraData(cellRef, "stick_style", 0);
                ContentValues contentValues = new ContentValues();
                contentValues.put("cell_data", cellRef.appendExtraData);
                int id = this.mSQLiteDatabase.update("v30_category_list", contentValues, "cell_id =?  AND category =?  AND cell_type =?", whereArgs);
                StringBuilder stringBuilder = new StringBuilder("cancel last stick:").append(cellId).append(";result:");
                Logger.d("tag_stick", stringBuilder.append(id > 0).toString());
                continue;
            }
        } catch (Exception exception) {
            Logger.throwExceptionInDebug(exception);
            Logger.d("tag_stick", "error");
        } finally {
            closeQuietlyAndEndTransaction(null, this.mSQLiteDatabase);
            Logger.d("tag_stick", "done");
        }
    }

    private void insertArticleList(List<CellRef> cellRefList, String category, boolean arg29, boolean[] arg30) {
        ContentValues contentValues;
        int v7_2;
        long v8;
        Article article;
        Object v11;
        Cursor v12;
        Iterator v23;
        String[] v13;
        String[] whereArgs;
        String limit;
        String[] selectionArgs;
        String selection;
        String[] columns;
        boolean v20 = "__all__".equals(category);
        boolean v21 = android.support.design.a.isTextEmpty(category);
        Cursor cursor = null;
        int v2 = 14;
        try {
            columns = new String[v2];
            columns[0] = "user_repin";
            columns[1] = "user_digg";
            columns[2] = "user_bury";
            columns[3] = "digg_count";
            columns[4] = "bury_count";
            columns[5] = "user_repin_time";
            columns[6] = "read_timestamp";
            columns[7] = "max_behot_time";
            columns[8] = "user_dislike";
            columns[9] = "ban_comment";
            columns[10] = "web_type_loadtime";
            columns[11] = "web_tc_loadtime";
            columns[12] = "item_version";
            columns[13] = "ext_json";
            selection = "item_id =?  AND group_item_id = ?";
            selectionArgs = new String[]{"0", "0"};
            limit = "1";
            whereArgs = new String[]{"0", category, "0"};
            v13 = new String[]{"group_id", "item_id", "aggr_type", "image_detail", "thumb_image"};
            v23 = cellRefList.iterator();
            v12 = cursor;
            while (true) {
                if (!v23.hasNext()) {
                    closeQuietly(v12);
                    return;
                }
                v11 = v23.next();
                article = ((CellRef) v11).article;
                if (((CellRef) v11).cellType != 0) {
                    continue;
                }

                if (article == null) {
                    continue;
                }

                article.userRepin = false;
                article.statsTimestamp = System.currentTimeMillis();
                selectionArgs[0] = String.valueOf(article.groupId);
                selectionArgs[1] = String.valueOf(article.itemId);
                whereArgs[0] = article.getItemKey();
                cursor = this.mSQLiteDatabase.query(
                        "v30_article",
                        columns,
                        selection,
                        selectionArgs,
                        null,
                        null,
                        null,
                        limit);
                v2 = 0;
                v8 = 0;
                if (!cursor.moveToNext()) {
                    v7_2 = 0;
                    v2 = 0;
                } else {
                    article.clickTimestamp = cursor.getLong(6);
                    String extJson = cursor.getString(13);
                    if (android.support.design.a.isTextEmpty(extJson)) {

                    } else {
                        try {
                            article.impressionTimestamp = new JSONObject(extJson).optLong("impression_timestamp");
                        } catch (JSONException jsonException) {
                        }
                        v7_2 = article.rebackFlag > 0 ? 1 : 0;
                        if (v7_2 != 0) {
                            v7_2 = article.clickTimestamp > 0 || article.impressionTimestamp > 0 ? 1 : 0;
                            if (v7_2 != 0) {
                                if (arg30 != null && arg30.length > 0) {
                                    arg30[0] = true;
                                }
                                v23.remove();
                                closeQuietly(cursor);
                                v12 = cursor;
                                continue;
                            }
                        }
                    }

                    boolean v7_3 = cursor.getInt(0) > 0 ? true : false;
                    article.userRepin = v7_3;
                    if (cursor.getInt(1) > 0) {
                        article.userDigg = true;
                    }

                    if (cursor.getInt(2) > 0) {
                        article.userBury = true;
                    }

                    v7_2 = cursor.getInt(3);
                    int v8_1 = cursor.getInt(4);
                    if (v7_2 > article.diggCount) {
                        article.diggCount = v7_2;
                    }

                    if (v8_1 > article.buryCount) {
                        article.buryCount = v8_1;
                    }

                    article.userRepinTime = cursor.getLong(5);
                    v8 = cursor.getLong(7);
                    boolean userDislike = cursor.getInt(8) > 0;
                    article.userDislike = userDislike;
                    if (cursor.getInt(9) > 0) {
                        article.mBanComment = true;
                    }

                    article.webTypeLoadTime = cursor.getLong(10);
                    article.webTcLoadTime = cursor.getLong(11);
                    if ((article.a(cursor.getLong(12))) && ((article.userDislike) || article.clickTimestamp > 0)) {
                        v2 = 1;
                    }
                    v7_2 = v2;
                    v2 = 1;
                }
                closeQuietly(cursor);
                if (v2 != 0) {
                    contentValues = article2ContentValues(article, true, v20);
                    if (v8 > article.behotTime) {
                        contentValues.put("max_behot_time", Long.valueOf(v8));
                    }

                    if (v7_2 != 0) {
                        article.clickTimestamp = 0;
                        article.userDislike = false;
                        contentValues.put("read_timestamp", Long.valueOf(0));
                        contentValues.put("user_dislike", Integer.valueOf(0));
                    }

                    this.mSQLiteDatabase.update("v30_article", contentValues, selection, selectionArgs);
                } else {
                    contentValues = article2ContentValues(article, false, v20);
                    if (v8 > article.behotTime) {
                        contentValues.put("max_behot_time", Long.valueOf(v8));
                    }

                    this.mSQLiteDatabase.insert("v30_article", null, contentValues);
                }

                if (!v21) {
                    contentValues = new ContentValues();
                    contentValues.put("cate_behot_time", Long.valueOf(((CellRef) v11).cateBehotTime));
                    contentValues.put("cate_cursor", Long.valueOf(((CellRef) v11).cateCursor));
                    contentValues.put("cell_type", Integer.valueOf(0));
                    contentValues.put("cell_data", ((CellRef) v11).appendExtraData);
                    contentValues.put("ad_id", Long.valueOf(((CellRef) v11).adId));
                    if (this.mSQLiteDatabase.update("v30_category_list", contentValues,
                            "cell_id =?  AND category =?  AND cell_type =?", whereArgs) <= 0) {
                        contentValues.put("category", category);
                        contentValues.put("cell_id", article.getItemKey());
                        this.mSQLiteDatabase.insert("v30_category_list", null, contentValues);
                    }
                }

                if ((arg29) && (article.userDislike)) {
                    v23.remove();
                    v12 = cursor;
                } else {
                    cursor = this.mSQLiteDatabase.query("v30_detail", v13, "group_id =?  AND item_id = ?",
                            selectionArgs, null, null, null, "1");
                    if (cursor.moveToNext()) {
                        article.isDetailLoaded = true;
                    }
                    closeQuietly(cursor);
                    v12 = cursor;
                }
                continue;
            }
        } catch (Exception v2_2) {
            Logger.w("DBHelper", "insert article list exception: " + v2_2);
        } finally {
            closeQuietly(cursor);
        }
    }

    public final int queryCategoryShowEtStatus(String categoryName, int isCategory) {
        String[] columns = new String[]{"show_et_status"};
        String selection = isCategory == 1 ? "category_name=?" : "concern_id=?";
        String[] selectionArgs = new String[]{categoryName};
        try {
            Cursor cursor = this.mSQLiteDatabase.query("v38_category_meta",
                    columns, selection, selectionArgs, null, null, null);
            if (cursor == null) {
                return 0;
            }

            if (!cursor.moveToFirst()) {
                return 0;
            }
            int showEtStatus = cursor.getInt(0);
            closeQuietly(cursor);
            return showEtStatus;
        } catch (Exception e) {
            Logger.w("DBHelper", "query category show et status exception: " + e);
        }
        return 0;
    }

    @SuppressLint(value = {"UseSparseArrays"})
    public final int insertSubscribeList(List arg19, String arg20) {
        int v2_5;
        Cursor v2_4;
        int v3_2 = 0;
        Iterator v8_1;
        ContentValues v7;
        int v4_1;
        Cursor v3_1 = null;
        String[] selectionArgs;
        String selection;
        Object v2_2;
        long v12 = 0;
        synchronized (this) {
            try {
                if (Logger.debug()) {
                    Logger.d("DBHelper", "begin insertSubscribeList, isLogin=false");
                }

                v12 = System.currentTimeMillis();
                if (arg19 == null || arg19.isEmpty() || (this.isSQLiteDatabaseAvailable())) {
                    return 0;
                }
                HashMap v11 = new HashMap();
                if (!arg19.isEmpty()) {
                    Iterator v3 = arg19.iterator();
                    while (v3.hasNext()) {
                        v2_2 = v3.next();
                        v11.put(Long.valueOf(((com.ss.android.article.base.feature.subscribe.model.d) v2_2).b), v2_2);
                    }
                }

                this.mSQLiteDatabase.beginTransaction();
                selection = "e_group_id=?";
                selectionArgs = new String[]{"-1"};
                String[] columns = new String[]{"e_entry_id", "e_list_order", "e_int_value", "e_str_value", "e_time_value", "e_ext_json"};
                if (!v11.isEmpty()) {
                    v3_1 = this.mSQLiteDatabase.query("v27_entry_group", columns, selection, selectionArgs, null, null, null);
                    Logger.w("DBHelper", "sub count " + v3_1.getCount());
                    while (true) {
                        if (v3_1.moveToNext()) {
                            long entryId = v3_1.getLong(0);
                            v4_1 = v3_1.getInt(2);
                            long v14 = v3_1.getLong(4);
                            if (entryId > 0) {
                                v2_2 = v11.get(Long.valueOf(entryId));
                            } else {
                                v2_2 = null;
                            }
                            if (v2_2 == null) {
                                continue;
                            }

                            if (((com.ss.android.article.base.feature.subscribe.model.d) v2_2).lastTime != v14) {
                                continue;
                            }

                            if (((com.ss.android.article.base.feature.subscribe.model.d) v2_2).badge <= 0) {
                                continue;
                            }
                            ((com.ss.android.article.base.feature.subscribe.model.d) v2_2).badge = v4_1;
                            continue;
                        } else {
                            v3_1.close();
                            break;
                        }
                    }
                }

                this.mSQLiteDatabase.delete("v27_entry_group", selection, selectionArgs);
                selection = "id=?";
                selectionArgs = new String[]{"0"};
                v7 = new ContentValues();
                v8_1 = arg19.iterator();
                v4_1 = 1000;
                v3_2 = 0;
                while (v8_1.hasNext()) {
                    v2_2 = v8_1.next();
                    ++v4_1;
                    v7.clear();
                    v7.put("e_group_id", Integer.valueOf(-1));
                    v7.put("e_entry_id", Long.valueOf(((com.ss.android.article.base.feature.subscribe.model.d) v2_2).b));
                    v7.put("e_list_order", Integer.valueOf(v4_1));
                    v7.put("e_int_value", Integer.valueOf(((com.ss.android.article.base.feature.subscribe.model.d) v2_2).badge));
                    v7.put("e_str_value", ((com.ss.android.article.base.feature.subscribe.model.d) v2_2).itemDescription);
                    v7.put("e_time_value", Long.valueOf(((com.ss.android.article.base.feature.subscribe.model.d) v2_2).lastTime));
                    this.mSQLiteDatabase.insert("v27_entry_group", null, v7);
                    EntryItem v2_3 = ((com.ss.android.article.base.feature.subscribe.model.d) v2_2).a;
                    selectionArgs[0] = String.valueOf(v2_3.mId);
                    ContentValues v9 = entryItem2ContentValues(true, v2_3, v2_3.isSubscribed());
                    if (this.mSQLiteDatabase.update("v27_entry", v9, selection, selectionArgs) <= 0) {
                        v9.put("id", Long.valueOf(v2_3.mId));
                        this.mSQLiteDatabase.insert("v27_entry", null, v9);
                    }

                    ++v3_2;
                }

                selectionArgs[0] = "subscribe_list";
                this.mSQLiteDatabase.delete("misc_kv", "name=?", selectionArgs);
                if (!android.support.design.a.isTextEmpty(arg20)) {
                    v7.clear();
                    v7.put("name", "subscribe_list");
                    v7.put("str_value", arg20);
                    this.mSQLiteDatabase.insert("misc_kv", null, v7);
                }

                this.mSQLiteDatabase.setTransactionSuccessful();
                v2_5 = v3_2;
                if (Logger.debug()) {
                    Logger.v("DBHelper", "end insertSubscribeList: time=" + (System.currentTimeMillis() - v12) + ", count=" + v2_5);
                }
                return v2_5;
            } catch (Exception v2_1) {
                Logger.w("DBHelper", "insert subscribe list: " + v2_1);
                v2_5 = v3_2;
                if (Logger.debug()) {
                    Logger.v("DBHelper", "end insertSubscribeList: time=" + (System.currentTimeMillis() - v12) + ", count=" + v2_5);
                }
                return v2_5;
            } finally {
                closeQuietlyAndEndTransaction(v3_1, this.mSQLiteDatabase);
            }
        }
    }

    public final long insertDetail(Article article, ArticleDetail articleDetail, String cacheToken, String imageDetail, String thumbImage, long arg12) {
        synchronized (this) {
            try {
                if (article.opItemType != ItemType.ARTICLE) {
                    return 0L;
                }

                if (article.groupId <= 0L) {
                    return 0L;
                }

                if (!this.isSQLiteDatabaseAvailable()) {
                    return 0L;
                }
                String[] whereArgs = new String[2];
                whereArgs[0] = String.valueOf(article.groupId);
                whereArgs[1] = String.valueOf(article.itemId);
                this.mSQLiteDatabase.delete("v30_detail", "group_id =?  AND item_id = ?", whereArgs);
                ContentValues contentValues = new ContentValues();
                contentValues.put("group_id", Long.valueOf(article.groupId));
                contentValues.put("item_id", Long.valueOf(article.itemId));
                contentValues.put("aggr_type", Integer.valueOf(article.aggrType));
                contentValues.put("content", articleDetail.content);
                if (imageDetail == null) {
                    imageDetail = "";
                }
                if (thumbImage == null) {
                    thumbImage = "";
                }
                contentValues.put("image_detail", imageDetail);
                contentValues.put("thumb_image", thumbImage);
                if (cacheToken == null) {
                    cacheToken = "";
                }
                contentValues.put("cache_token", cacheToken);
                contentValues.put("timestamp", Long.valueOf(articleDetail.timestamp));
                contentValues.put("expire_seconds", Long.valueOf(arg12));
                if (!android.support.design.a.isTextEmpty(articleDetail.extJson)) {
                    contentValues.put("ext_json", articleDetail.extJson);
                }

                if (!TextUtils.isEmpty(articleDetail.novelDataJson)) {
                    contentValues.put("serial_data", articleDetail.novelDataJson);
                }

                return this.mSQLiteDatabase.insert("v30_detail", null, contentValues);
            } catch (Exception exception) {
                Logger.w("DBHelper", "insert detail exception: " + exception);
            }
        }
        return 0L;
    }

    public final SSDBHelper.a$a a(ItemType arg3) {
        SSDBHelper.a$a v0;
        switch (com.ss.android.article.base.feature.app.b.d.a[arg3.ordinal()]) {
            case 1: {
                v0 = this.z;
                break;
            }
            default: {
                v0 = null;
                break;
            }
        }

        return v0;
    }

    public final List<CellRef> queryFavor(long userRepinTime, int limit) {
        ArrayList<CellRef> cellRefList = new ArrayList();
        Iterator<Article> iterator = this.queryRecentOrFavor0(userRepinTime, limit).iterator();
        while (iterator.hasNext()) {
            Article article = iterator.next();
            cellRefList.add(new CellRef("__favor__", article.behotTime, article));
        }

        this.g(cellRefList);
        Collections.sort(cellRefList, new CellRefComparator(1));
        ArrayList<CellRef> subList = new ArrayList();
        try {
            subList.addAll(cellRefList.subList(0, Math.min(limit, cellRefList.size())));
        } catch (Exception exception) {
            Logger.e("DBHelper", "exception in queryFavor : " + exception.toString());
        }
        return subList;
    }

    public final List queryRecent(long arg24, int arg26, String category, boolean[] arg28, long[] arg29) {
        List v2_5;
        long v6;
        int v2_3;
        long v4;
        long v12;
        long v14;
        Cursor v16;
        long v18;
        ArrayList v11 = null;
        synchronized (this) {
            Cursor cursor = null;
            try {
                v11 = new ArrayList();
                if (!this.isSQLiteDatabaseAvailable()) {
                    return v11;
                }
                if (!android.support.design.a.isTextEmpty(category) && arg26 > 0) {
                    v18 = System.currentTimeMillis();
                    v16 = null;
                    v14 = 0;
                    v12 = 0;
                    if (arg24 <= 0) {
                        cursor = this.mSQLiteDatabase.query("article_category",
                                article_category_colums,
                                "category=?",
                                new String[]{category},
                                null,
                                null,
                                null,
                                "1");
                        if (cursor.moveToNext()) {
                            v4 = System.currentTimeMillis();
                            arg29[0] = Math.max(cursor.getLong(1), cursor.getLong(2));
                            if (arg29[0] > v4) {
                                arg29[0] = v4;
                            }
                            v4 = cursor.getLong(3);
                            v2_3 = 4;
                            v12 = cursor.getLong(v2_3);
                            v6 = v4;
                            v4 = v12;
                        } else {
                            v4 = v12;
                            v6 = v14;
                        }
                        cursor.close();
                        cursor = null;
                    } else {
                        v4 = v12;
                        v6 = v14;
                        cursor = v16;
                    }
                    if (v6 > 0 && v4 > 0 && v6 > v4) {
                        arg28[0] = true;
                        long v20 = v4;
                        v4 = v6;
                        v6 = v20;
                    } else {
                        v4 = 0;
                        arg28[0] = false;
                        v6 = v4;
                        v4 = arg24;
                    }
                    Cursor v2_4 = null;
                    closeQuietly(v2_4);
                    ((List) v11).addAll(this.queryCategory(category, v4, v6, arg26, ItemType.ARTICLE));
                    ((List) v11).addAll(this.queryCategory(category, v4, v6, arg26, ItemType.ESSAY));
                    ((List) v11).addAll(this.queryCategory(category, v4, v6, arg26, ItemType.TOPIC));
                    ((List) v11).addAll(this.queryEmbeddedCell(category, v4, v6, arg26));
                    Collections.sort(v11, new CellRefComparator(0));
                    Logger.v("DBHelper", "queryCategory time: " + (System.currentTimeMillis() - v18) + " " + category + " " + ((List) v11).size());
                    this.g(((List) v11));
                    return ((List) v11).subList(0, Math.min(((List) v11).size(), arg26));
                } else {
                    return v11;
                }
            } catch (Exception v2_2) {
                Logger.d("DBHelper", "queryRecent - Query TABLE_CATEGORY_REFRESH failed.", v2_2);
            } finally {
                closeQuietly(cursor);

            }
            return v11;
        }
    }

    public final void a(int arg4) {
        synchronized (this) {
            if (this.isSQLiteDatabaseAvailable()) {
                ContentValues contentValues = new ContentValues();
                contentValues.put("ss_op_key", Integer.valueOf(106));
                contentValues.put("type", Integer.valueOf(arg4));
                contentValues.put("search_word", "");
                this.asyncUpdate(contentValues);
            }
        }
    }

    public final void a(int arg13, ContentValues arg14) {
        String[] v0_10;
        int v1_2;
        String v9 = null;
        int v8 = 2;
        long v10 = 0;
        int v6 = 0;
        if (arg14 == null) {
            return;
        }

        if (arg14.size() == 0) {
            return;
        }

        switch (arg13) {
            case 1: {
                Long v2_1 = arg14.getAsLong("item_id");
                if (v2_1 == null) {
                    return;
                }

                if (v2_1.longValue() <= v10) {
                    return;
                }

                Long v0_2 = Long.valueOf(v10);
                Long v1_1 = arg14.containsKey("group_item_id") ? arg14.getAsLong("group_item_id") : v0_2;
                Integer v0_3 = arg14.getAsInteger("op_item_type");
                if (v0_3 == null) {
                    return;
                }

                ItemType v3 = ItemType.fromValue(v0_3.intValue());
                if (v3 == null) {
                    return;
                }

                if (this.a(v3) == null) {
                    return;
                }

                StringBuilder v0_4 = new StringBuilder();
                ArrayList v4 = new ArrayList();
                v0_4.append(" item_id = ? ");
                v4.add(String.valueOf(v2_1));
                if (v1_1.longValue() > v10) {
                    v0_4.append(" or group_item_id = ? ");
                    v4.add(String.valueOf(v1_1));
                }
                String v5_1 = v0_4.toString();
                Object[] v0_5 = v4.toArray(new String[v4.size()]);
                Logger.d("DBHelper", "no Tag favor or unfavor， item_id:" + v1_1 + "; group_id:" + v2_1);
                arg14.remove("op_item_type");
                arg14.remove("item_id");
                arg14.remove("group_item_id");
                arg14.remove("tag");
                if (arg14.size() <= 0) {
                    return;
                }
                String v1 = this.b(v3);
                if (android.support.design.a.isTextEmpty(v1)) {
                    return;
                }

                this.mSQLiteDatabase.update(v1, arg14, v5_1, ((String[]) v0_5));
                return;
            }
            case 11: {
                if (!arg14.containsKey("type")) {
                    return;
                }
                if (!arg14.containsKey("key")) {
                    return;
                }
                if (!arg14.containsKey("time")) {
                    return;
                }
                int v0 = arg14.getAsInteger("type").intValue();
                String v1 = arg14.getAsString("key");
                long v2 = arg14.getAsLong("time").longValue();
                String[] v5 = new String[3];
                v5[0] = String.valueOf(v0);
                v5[1] = v1;
                v5[v8] = String.valueOf(v2);
                Logger.d("NetRequestModel", "result of delete:" + (((long) this.mSQLiteDatabase.delete("net_request_queue", "type=? AND key =? AND time=? ", v5))) + ";values:" + arg14);
                return;
            }
            case 12: {
                if (!arg14.containsKey("type")) {
                    return;
                }

                if (!arg14.containsKey("key")) {
                    return;
                }

                if (!arg14.containsKey("time")) {
                    return;
                }

                Logger.d("NetRequestModel", "result of insert or replace:" + this.mSQLiteDatabase.replace("net_request_queue", v9, arg14) + ";values:" + arg14);
                super.a(arg13, arg14);
                return;
            }
            case 101: {
                if (arg14.size() < v8) {
                    return;
                }

                String v0_9 = arg14.getAsString("category");
                if (android.support.design.a.isTextEmpty(v0_9)) {
                    return;
                }

                arg14.remove("category");
                if (this.mSQLiteDatabase.update("article_category", arg14, "category=?", new String[]{v0_9}) > 0) {
                    return;
                }

                arg14.put("category", v0_9);
                this.mSQLiteDatabase.insert("article_category", v9, arg14);
                return;
            }
            case 102: {
                this.i();
                return;
            }
            case 103: {
                if (arg14.size() < 3) {
                    return;
                }

                if (!arg14.containsKey("user_id")) {
                    return;
                }

                if (!arg14.containsKey("update_id")) {
                    return;
                }

                if (!arg14.containsKey("item_json")) {
                    return;
                }

                long v0_1 = arg14.getAsLong("user_id").longValue();
                long v2 = arg14.getAsLong("update_id").longValue();
                arg14.remove("user_id");
                arg14.remove("update_id");
                String[] v5 = new String[v8];
                v5[0] = String.valueOf(v0_1);
                v5[1] = String.valueOf(v2);
                this.mSQLiteDatabase.update("update_item", arg14, "user_id=? AND update_id=?", v5);
                return;
            }
            case 104: {
                if (arg14.size() <= 0) {
                    return;
                }
                if (!arg14.containsKey("update_id")) {
                    return;
                }
                this.mSQLiteDatabase.delete("update_item", "update_id=?", new String[]{String.valueOf(arg14.getAsLong("update_id").longValue())});
                return;
            }
            case 105: {
                if (arg14.size() < v8) {
                    return;
                }

                int v0 = arg14.getAsInteger("type").intValue();
                long v2 = this.getSearchWordList(v0, arg14.getAsString("search_word"));
                if (v2 == -1) {
                    this.mSQLiteDatabase.insert("search_word", v9, arg14);
                    return;
                }

                String[] v4_1 = new String[v8];
                v4_1[0] = String.valueOf(v2);
                v4_1[1] = String.valueOf(v0);
                this.mSQLiteDatabase.update("search_word", arg14, "id=? and type=?", v4_1);
                return;
            }
            case 106: {
                if (arg14.size() <= 0) {
                    return;
                }
                int v3_1 = arg14.getAsInteger("type").intValue();
                String v0_9 = arg14.containsKey("search_word") ? arg14.getAsString("search_word") : v9;
                String v2_3 = "type=?";
                String[] v1_3 = new String[]{String.valueOf(v3_1)};
                String v1;
                if (!android.support.design.a.isTextEmpty(v0_9)) {
                    v1_3 = new String[v8];
                    v1_3[0] = String.valueOf(v3_1);
                    v1_3[1] = v0_9;
                    v0_10 = v1_3;
                    v1 = "type=? and search_word=?";
                } else {
                    v0_10 = v1_3;
                    v1 = v2_3;
                }

                int v0 = this.mSQLiteDatabase.delete("search_word", v1, v0_10);
                if (Logger.debug()) {
                    Logger.d("suggestion", "clearSearchWordList type = " + String.valueOf(v3_1) + " count= " + String.valueOf(v0));
                }
                return;
            }
            case 107: {
                if (arg14.size() <= 0) {
                    return;
                }

                if (!arg14.containsKey("item_id")) {
                    return;
                }

                long v2 = arg14.getAsLong("item_id").longValue();
                if (v2 <= v10) {
                    return;
                }

                long v4_2 = arg14.containsKey("group_item_id") ? arg14.getAsLong("group_item_id").longValue() : v10;
                if (v4_2 < v10) {
                    return;
                }

                if (arg14.containsKey("aggr_type")) {
                    v6 = arg14.getAsInteger("aggr_type").intValue();
                }

                this.f(new Article(v2, v4_2, v6));
                return;
            }
            case 110: {
                String v0_9 = arg14.getAsString("category");
                v1_2 = arg14.getAsInteger("cell_type").intValue();
                String v2_3 = arg14.getAsString("cell_id");
                if (android.support.design.a.isTextEmpty(v0_9)) {
                    return;
                }

                if (android.support.design.a.isTextEmpty(v2_3)) {
                    return;
                }

                String[] v3_2 = new String[3];
                v3_2[0] = v2_3;
                v3_2[1] = v0_9;
                v3_2[v8] = String.valueOf(v1_2);
                arg14.remove("cell_type");
                arg14.remove("category");
                arg14.remove("cell_id");
                if (arg14.size() <= 0) {
                    return;
                }

                this.mSQLiteDatabase.update("v30_category_list", arg14, "cell_id =?  AND category =?  AND cell_type =?", v3_2);
                return;
            }
            case 111: {
                if (arg14.size() >= 3 && (arg14.containsKey("category")) && (arg14.containsKey("cell_type")) && (arg14.containsKey("cell_id"))) {
                    String v0_9 = arg14.getAsString("cell_id");
                    v1_2 = arg14.getAsInteger("cell_type").intValue();
                    String v2_3 = arg14.getAsString("category");
                    if (android.support.design.a.isTextEmpty(v0_9)) {
                        return;
                    }

                    if (android.support.design.a.isTextEmpty(v2_3)) {
                        return;
                    }

                    if (!CellRef.isValidCellType(v1_2)) {
                        return;
                    }

                    String[] v3_2 = new String[3];
                    v3_2[0] = v0_9;
                    v3_2[1] = v2_3;
                    v3_2[v8] = String.valueOf(v1_2);
                    this.mSQLiteDatabase.delete("v30_category_list", "cell_id =?  AND category =?  AND cell_type =?", v3_2);
                }
                return;
            }
            case 115: {
                long v2 = arg14.getAsLong("group_id").longValue();
                if (v2 <= v10) {
                    return;
                }

                long v0_1 = arg14.containsKey("item_id") ? arg14.getAsLong("item_id").longValue() : v10;
                String[] v4_1 = new String[v8];
                v4_1[0] = String.valueOf(v2);
                v4_1[1] = String.valueOf(v0_1);
                String[] v2_2 = new String[]{"ext_json"};
                String v7 = "max_behot_time DESC";
                String v8_1 = "1";
                try {
                    Cursor v0_7 = this.mSQLiteDatabase.query("v30_article", v2_2, "item_id =?  AND group_item_id = ?", v4_1, null, null, v7, v8_1);
                    if (v0_7.moveToNext()) {
                        v9 = v0_7.getString(0);
                    }

                    closeQuietly(v0_7);
                    JSONObject v0_8 = android.support.design.a.isTextEmpty(v9) ? new JSONObject() : new JSONObject(v9);
                    if (arg14.containsKey("impression_timestamp")) {
                        long impressionTimestamp = arg14.getAsLong("impression_timestamp").longValue();
                        if (impressionTimestamp > v10) {
                            v0_8.put("impression_timestamp", impressionTimestamp);
                        }
                    }

                    if (arg14.containsKey("video_id")) {
                        String v1 = arg14.getAsString("video_id");
                        if (!android.support.design.a.isTextEmpty(v1)) {
                            v0_8.put("video_id", v1);
                        }
                    }

                    if (arg14.containsKey("video_duration")) {
                        int videoDuration = arg14.getAsInteger("video_duration").intValue();
                        if (videoDuration > 0) {
                            v0_8.put("video_duration", videoDuration);
                        }
                    }

                    if (arg14.containsKey("ad_video_click_track_urls")) {
                        String v1 = arg14.getAsString("ad_video_click_track_urls");
                        if (!android.support.design.a.isTextEmpty(v1)) {
                            v0_8.put("ad_video_click_track_urls", v1);
                        }
                    }

                    if (arg14.containsKey("media_name")) {
                        String v1 = arg14.getAsString("media_name");
                        if (!android.support.design.a.isTextEmpty(v1)) {
                            v0_8.put("media_name", v1);
                        }
                    }

                    arg14.clear();
                    arg14.put("ext_json", v0_8.toString());
                    this.mSQLiteDatabase.update("v30_article", arg14, "item_id =?  AND group_item_id = ?", v4_1);
                } catch (Exception v0_6) {
                    Logger.w("DBHelper", "save article impression exception: " + v0_6.toString());
                }
                return;
            }
            case 116: {
                if (arg14.size() <= 0) {
                    return;
                }

                if (!arg14.containsKey("ad_id")) {
                    return;
                }

                long v0_1 = arg14.getAsLong("ad_id").longValue();
                if (v0_1 <= v10) {
                    return;
                }

                this.h(v0_1);
                return;
            }
        }

        super.a(arg13, arg14);
        return;


    }

    public final void a(int arg13, Object arg14) {
        Cursor v0_4;
        Cursor v1_3 = null;
        String orderBy;
        Cursor v10 = null;
        int v8 = 1;
        int v9 = 0;
        switch (arg13) {
            case 108: {
                if (!(arg14 instanceof com.ss.android.article.base.feature.subscribe.model.d)) {
                    return;
                }
                String[] entryId = new String[]{"-1", String.valueOf(((com.ss.android.article.base.feature.subscribe.model.d) arg14).b)};
                ContentValues contentValues = new ContentValues();
                contentValues.put("e_int_value", Integer.valueOf(0));
                this.mSQLiteDatabase.update("v27_entry_group", contentValues, "e_group_id=? AND e_entry_id=?", entryId);
                return;
            }
            case 109: {
                if (!(arg14 instanceof Message)) {
                    return;
                }
                if (!(((Message) arg14).obj instanceof com.ss.android.article.base.feature.update.a.d)) {
                    if (v9 == 0) {
                        return;
                    }
                    if (((Message) arg14).getTarget() == null) {
                        return;
                    }
                    ((Message) arg14).sendToTarget();
                    return;
                }
                String selection = "update_id=?";
                String[] selectionArgs = new String[]{String.valueOf(((com.ss.android.article.base.feature.update.a.d) ((Message) arg14).obj).i)};
                orderBy = "1";
                try {
                    v1_3 = this.mSQLiteDatabase.query("update_item", update_item_colums, selection, selectionArgs, null, null, orderBy);
                    int v0;
                    if (!v1_3.moveToNext()) {
                        v0 = 0;
                    } else {
                        v0 = 1;
                    }

                    v9 = v0;
                } catch (Exception v0_1) {
                } finally {
                    closeQuietly(v1_3);
                }

                if (v9 == 0) {
                    return;
                }
                if (((Message) arg14).getTarget() == null) {
                    return;
                }
                ((Message) arg14).sendToTarget();
                return;
            }
            case 112: {
                if (!(arg14 instanceof CellRef)) {
                    return;
                }
                this.updateCategoryList(((CellRef) arg14), false);
                return;
            }
            case 117: {
                if ((arg14 instanceof MediaInfo)) {

                    ((MediaInfo) arg14).modifyTime = System.currentTimeMillis();
                    ContentValues v0_5 = new ContentValues();
                    v0_5.put("id", Long.valueOf(((MediaInfo) arg14).id));
                    v0_5.put("modify_time", Long.valueOf(((MediaInfo) arg14).modifyTime));
                    v0_5.put("avatarUrl", ((MediaInfo) arg14).avatarUrl);
                    v0_5.put("description", ((MediaInfo) arg14).description);
                    v0_5.put("name", ((MediaInfo) arg14).name);
                    v0_5.put("scheme", ((MediaInfo) arg14).scheme);
                    String v1_1 = "user_verified";
                    if (!((MediaInfo) arg14).userVerified) {
                        v8 = 0;
                    }
                    v0_5.put(v1_1, Integer.valueOf(v8));
                    v0_5.put("extraJson", MediaInfo.a());
                    Logger.d("SubscribedVideoPgcManager", "video subscribe，add data:" + this.mSQLiteDatabase.replace("subscribed_video_pgc_user", ((String) null), v0_5)
                            + "; id:" + ((MediaInfo) arg14).id
                            + ",name:" + ((MediaInfo) arg14).name);
                }
                return;
            }
            case 118: {
                if (!(arg14 instanceof MediaInfo)) {
                    return;
                }
                int v0 = this.mSQLiteDatabase.delete("subscribed_video_pgc_user", "id=? ", new String[]{((MediaInfo) arg14).id + ""});
                String v1_1 = "SubscribedVideoPgcManager";
                StringBuilder v2_1 = new StringBuilder("video subscribe，delete data:");
                boolean v8_1 = v0 > 0;
                Logger.d(v1_1, v2_1.append(v8_1).append("; id:").append(((MediaInfo) arg14).id).append(",name:").append(((MediaInfo) arg14).name).toString());
                return;
            }
            case 119: {
                if (!(arg14 instanceof List)) {
                    return;
                }
                try {
                    this.mSQLiteDatabase.beginTransaction();
                    Logger.d("SubscribedVideoPgcManager", "video subscribe ，start all replace");
                    this.mSQLiteDatabase.delete("subscribed_video_pgc_user", "1", null);
                    Logger.d("SubscribedVideoPgcManager", "video subscribe，1. have delete all old datas");
                    long v4 = System.currentTimeMillis();
                    Iterator v3 = ((List) arg14).iterator();
                    int v1_2;
                    int v2_2;
                    for (v1_2 = 0; v3.hasNext(); v1_2 = v2_2) {
                        Object v0_3 = v3.next();
                        ContentValues v6 = new ContentValues();
                        v2_2 = v1_2 + 1;
                        ((MediaInfo) v0_3).modifyTime = v4 - (((long) v1_2));
                        v6.put("id", Long.valueOf(((MediaInfo) v0_3).id));
                        v6.put("modify_time", Long.valueOf(((MediaInfo) v0_3).modifyTime));
                        v6.put("avatarUrl", ((MediaInfo) v0_3).avatarUrl);
                        v6.put("description", ((MediaInfo) v0_3).description);
                        v6.put("name", ((MediaInfo) v0_3).name);
                        v6.put("scheme", ((MediaInfo) v0_3).scheme);
                        orderBy = "user_verified";
                        v1_2 = ((MediaInfo) v0_3).userVerified ? 1 : 0;
                        v6.put(orderBy, Integer.valueOf(v1_2));
                        v6.put("extraJson", MediaInfo.a());
                        Logger.d("SubscribedVideoPgcManager", "video subscribe，add data:" + this.mSQLiteDatabase.replace("subscribed_video_pgc_user", null, v6) + "; id:" + ((MediaInfo) v0_3).id + ",name:" + ((MediaInfo) v0_3).name);
                    }

                    this.mSQLiteDatabase.setTransactionSuccessful();
                    Logger.d("SubscribedVideoPgcManager", "video subscribe，2. have insert all datas");
                } catch (Exception exception) {
                    exception.printStackTrace();
                    Logger.d("SubscribedVideoPgcManager", "video subscribe，2. insert error");
                } finally {
                    this.mSQLiteDatabase.endTransaction();
                    Logger.d("SubscribedVideoPgcManager", "video subscribe，3. insert or replace doene");
                }
                return;
            }
            case 120: {
                if (!(arg14 instanceof CellRef)) {
                    return;
                }
                this.updateCategoryList(((CellRef) arg14), true);
                return;
            }
            case 122: {
                com.ss.android.article.base.feature.app.b.e.shrinkCache(this);
                return;
            }
            case 123: {
                this.k();
                return;
            }
        }

        super.a(arg13, arg14);
        return;


    }

    public final void a(int arg4, String arg5) {
        synchronized (this) {
            if (this.isSQLiteDatabaseAvailable()) {
                ContentValues v0_1 = new ContentValues();
                v0_1.put("ss_op_key", Integer.valueOf(106));
                v0_1.put("type", Integer.valueOf(arg4));
                v0_1.put("search_word", arg5);
                this.asyncUpdate(v0_1);
            }
        }
    }

    public final void a(int arg6, String arg7, long arg8) {
        synchronized (this) {
            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }
                ContentValues v0_2 = new ContentValues();
                v0_2.put("ss_op_key", Integer.valueOf(105));
                v0_2.put("type", Integer.valueOf(arg6));
                if (android.support.design.a.isTextEmpty(arg7)) {
                    throw new IllegalArgumentException("searchword is empty");
                }
                v0_2.put("search_word", arg7);
                v0_2.put("timestamp", Long.valueOf(arg8));
                this.asyncUpdate(v0_2);
            } catch (Exception v0_1) {
                Logger.w("DBHelper", "insert detail exception: " + v0_1);
            }
        }
    }

    public final void a(long arg6, long arg8, int arg10) {
        long v2 = 0;
        if (arg6 > v2 && arg8 >= v2 && arg10 >= 0) {
            ContentValues v0 = new ContentValues();
            v0.put("ss_op_key", Integer.valueOf(1));
            v0.put("op_item_type", Integer.valueOf(ItemType.ARTICLE.getValue()));
            v0.put("item_id", Long.valueOf(arg6));
            v0.put("group_item_id", Long.valueOf(arg8));
            v0.put("comment_count", Integer.valueOf(arg10));
            this.asyncUpdate(v0);
        }
    }

    public final void updateDetail(long groupId, long itemId, int aggrType, String cacheToken, long ts, long expireSecond) {
        synchronized (this) {
            if (groupId > 0) {
                this.updateDetail(new Article(groupId, itemId, aggrType), cacheToken, ts, expireSecond);
            }
        }
    }

    public final void saveWebLoadTime(long itemId, long groupItemId, long loadTime, boolean isTc) {
        if (itemId > 0L && groupItemId >= 0L) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(1));
            contentValues.put("op_item_type", Integer.valueOf(ItemType.ARTICLE.getValue()));
            contentValues.put("item_id", Long.valueOf(itemId));
            contentValues.put("group_item_id", Long.valueOf(groupItemId));
            if (isTc) {
                contentValues.put("web_tc_loadtime", Long.valueOf(loadTime));
            } else {
                contentValues.put("web_type_loadtime", Long.valueOf(loadTime));
            }
            this.asyncUpdate(contentValues);
        }
    }

    public final void updateArticleInfo(ArticleInfo articleInfo) {
        if (articleInfo != null && articleInfo.groupItemId > 0) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(1));
            contentValues.put("op_item_type", Integer.valueOf(ItemType.ARTICLE.getValue()));
            contentValues.put("item_id", Long.valueOf(articleInfo.itemId));
            contentValues.put("group_item_id", Long.valueOf(articleInfo.groupItemId));
            contentValues.put("user_digg", Integer.valueOf(articleInfo.userDigg ? 1 : 0));
            contentValues.put("user_bury", Integer.valueOf(articleInfo.userBury ? 1 : 0));
            int hasDataUpdate = 0;
            if (articleInfo.diggCount >= 0) {
                contentValues.put("digg_count", Integer.valueOf(articleInfo.diggCount));
                hasDataUpdate = 1;
            }

            if (articleInfo.buryCount >= 0) {
                contentValues.put("bury_count", Integer.valueOf(articleInfo.buryCount));
                hasDataUpdate = 1;
            }

            if (!android.support.design.a.isTextEmpty(articleInfo.shareUrl)) {
                contentValues.put("share_url", articleInfo.shareUrl);
                hasDataUpdate = 1;
            }

            if (!android.support.design.a.isTextEmpty(articleInfo.displayUrl)) {
                contentValues.put("display_url", articleInfo.displayUrl);
                hasDataUpdate = 1;
            }

            if (!android.support.design.a.isTextEmpty(articleInfo.displayTitle)) {
                contentValues.put("display_title", articleInfo.displayTitle);
                hasDataUpdate = 1;
            }

            if (hasDataUpdate == 0) {
                return;
            }
            contentValues.put("stats_timestamp", Long.valueOf(System.currentTimeMillis()));
            this.asyncUpdate(contentValues);
        }
    }

    public final void deleteOrCancelLastStickData(ArticleQueryObj articleQueryObj) {
        synchronized (this) {
            if (articleQueryObj != null) {
                if (!android.support.design.a.isTextEmpty(articleQueryObj.category)) {
                    Logger.d("tag_stick", "deleteOrCancelLastStickData; isRefreshing:" + articleQueryObj.isRefreshing
                            + ", category:" + articleQueryObj.category
                            + ", action: " + articleQueryObj.actionToLastStick);
                    if (articleQueryObj.actionToLastStick > 0 && (this.isSQLiteDatabaseAvailable())) {
                        int actionToLastStick = articleQueryObj.actionToLastStick;
                        String category = articleQueryObj.category;
                        List<CellRef> cellRefList = articleQueryObj.r;
                        if (cellRefList != null && cellRefList.size() != 0) {
                            this.deleteOrCancelOldStickDatas(cellRefList, actionToLastStick, category);
                            return;
                        }
                        Logger.d("tag_stick", "in memory，no last stick data");
                    }
                }
            }
        }
    }

    public final void a(CellRef cellRef) {
        if (cellRef != null
                && !android.support.design.a.isTextEmpty(cellRef.cellId)
                && !android.support.design.a.isTextEmpty(cellRef.appendExtraData)) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(110));
            contentValues.put("cell_type", Integer.valueOf(cellRef.cellType));
            contentValues.put("category", cellRef.category);
            contentValues.put("cell_id", cellRef.cellId);
            contentValues.put("cell_data", cellRef.appendExtraData);
            this.asyncUpdate(contentValues);
        }
    }

    public final void a(f arg5) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("ss_op_key", Integer.valueOf(11));
        contentValues.put("type", Integer.valueOf(arg5.mType));
        contentValues.put("key", arg5.mKey);
        contentValues.put("time", Long.valueOf(arg5.mTime));
        this.asyncUpdate(contentValues);
    }

    public final void updateCategoryRefreshTime(String categoryName) {
        synchronized (this) {
            if (android.support.design.a.isTextEmpty(categoryName)) {
                return;
            }

            if (!this.isSQLiteDatabaseAvailable()) {
                return;
            }

            try {
                String[] whereArgs = new String[]{categoryName};
                ContentValues contentValues = new ContentValues();
                contentValues.put("last_refresh_time", Long.valueOf(System.currentTimeMillis()));
                this.mSQLiteDatabase.update("article_category", contentValues, "category=?", whereArgs);
            } catch (Exception exception) {
                Logger.v("DBHelper", "updateCategoryRefreshTime exception: " + exception);
            }
        }
    }

    public final void insertArticleList(List<CellRef> cellRefList) {
        synchronized (this) {
            if (cellRefList.isEmpty() || this.mSQLiteDatabase == null || !this.mSQLiteDatabase.isOpen()) {
                return;
            }
            try {
                this.mSQLiteDatabase.beginTransaction();
                this.insertArticleList(cellRefList, null, false, null);
                this.mSQLiteDatabase.setTransactionSuccessful();
            } finally {
                closeQuietlyAndEndTransaction(null, this.mSQLiteDatabase);
            }
        }
    }

    public final void updateCategoryRange(List<CellRef> cellRefList, String categoryName, long arg26, long arg28, boolean isRefresh, boolean[] arg31) {
        long v16;
        long v14;
        long bottomTime;
        long topTime;
        synchronized (this) {
            Cursor cursor = null;
            try {
                if (cellRefList.isEmpty()) {
                    return;
                }
                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }
                int size = cellRefList.size();
                long operationStartTs = System.currentTimeMillis();
                this.mSQLiteDatabase.beginTransaction();
                this.insertArticleList(cellRefList, categoryName, true, arg31);
                if (!cellRefList.isEmpty() && !android.support.design.a.isTextEmpty(categoryName)) {
                    Iterator<CellRef> iterator = cellRefList.iterator();
                    while (iterator.hasNext()) {
                        this.updateCategoryList(iterator.next(), false);
                    }
                }
                if (android.support.design.a.isTextEmpty(categoryName)) {
                    cursor = null;
                } else if (arg26 <= 0) {
                    cursor = null;
                } else if (arg28 <= 0) {
                    cursor = null;
                } else if (arg26 > arg28) {
                    String whereClause = "category=?";
                    String[] whereArgs = new String[]{categoryName};
                    cursor = this.mSQLiteDatabase.query("article_category", article_category_colums, whereClause, whereArgs, null, null, null, "1");
                    topTime = 0;
                    bottomTime = 0;
                    if (cursor.moveToNext()) {
                        topTime = cursor.getLong(3);
                        v14 = cursor.getLong(4);
                        v16 = topTime;
                    } else {
                        v14 = bottomTime;
                        v16 = topTime;
                    }
                    if (v16 <= 0) {
                        bottomTime = arg28;
                        topTime = arg26;
                    } else if (v14 <= 0) {
                        bottomTime = arg28;
                        topTime = arg26;
                    } else if (v16 <= v14) {
                        bottomTime = arg28;
                        topTime = arg26;
                    } else if (arg28 > v16) {
                        bottomTime = arg28;
                        topTime = arg26;
                    } else if (arg26 >= v14) {
                        topTime = Math.max(arg26, v16);
                        bottomTime = Math.min(arg28, v14);
                    } else {
                        bottomTime = arg28;
                        topTime = arg26;
                    }
                    if (Logger.debug()) {
                        Logger.v("DBHelper", "update range " + categoryName
                                + ": " + arg26
                                + " " + arg28
                                + " " + v16
                                + " " + v14
                                + " " + topTime
                                + " " + bottomTime);
                    }
                    ContentValues contentValues = new ContentValues();
                    contentValues.put("top_time", Long.valueOf(topTime));
                    contentValues.put("bottom_time", Long.valueOf(bottomTime));
                    long now = System.currentTimeMillis();
                    if (isRefresh) {
                        contentValues.put("last_refresh_time", Long.valueOf(now));
                    } else {
                        contentValues.put("last_loadmore_time", Long.valueOf(now));
                    }

                    if (this.mSQLiteDatabase.update("article_category", contentValues, whereClause, whereArgs) <= 0) {
                        contentValues.put("category", categoryName);
                        this.mSQLiteDatabase.insert("article_category", null, contentValues);
                    }
                }
                this.mSQLiteDatabase.setTransactionSuccessful();
                Logger.v("DBHelper", "insert list: " + size + " in " + (System.currentTimeMillis() - operationStartTs) + " ms");
            } catch (Exception exception) {
                exception.printStackTrace();
            } finally {
                closeQuietlyAndEndTransaction(cursor, this.mSQLiteDatabase);
            }
        }
    }

    public final boolean a(long arg12, boolean arg14) {
        int v0_2;
        String v2;
        Cursor v1 = null;
        Cursor v10 = null;
        synchronized (this) {
            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    Cursor v0_4 = null;
                    closeQuietly(v0_4);
                    return arg14;
                }
                v1 = this.mSQLiteDatabase.query("v27_entry", new String[]{"is_subscribe"}, "id=?", new String[]{Long.toString(arg12)}, null, null, null);
                if (v1 == null) {
                    return arg14;
                }
                if (v1.moveToFirst()) {
                    v2 = "is_subscribe";
                    if (arg14) {
                        v0_2 = 1;
                    } else {
                        v0_2 = 0;
                    }
                    if (v1 != null) {
                        int v2_1 = v1.getColumnIndex(v2);
                        if (v2_1 >= 0) {
                            v0_2 = v1.getInt(v2_1);
                        }
                    }
                    boolean v0_3 = v0_2 != 0 ? true : false;
                    arg14 = v0_3;
                    return arg14;
                }

                return arg14;
            } catch (Exception v0_1) {
                return arg14;
            } finally {
                closeQuietly(v1);
            }
        }
    }

    public final boolean a(EntryItem arg9, boolean arg10) {
        boolean v0 = false;
        synchronized (this) {
            if (!this.isSQLiteDatabaseAvailable()) {
                return false;
            }

            if (arg9.mId <= 0) {
                return false;
            }

            String v3 = "id=?";
            String[] v4 = new String[]{String.valueOf(arg9.mId)};
            ContentValues v5 = new ContentValues();
            int v2 = arg10 ? 1 : 0;
            v5.put("is_subscribe", Integer.valueOf(v2));
            if (this.mSQLiteDatabase.update("v27_entry", v5, v3, v4) > 0) {
                return true;
            }

            if ((arg10) && !arg9.isIdOnly()) {
                this.mSQLiteDatabase.insert("v27_entry", null, entryItem2ContentValues(false, arg9, arg10));
            }
            return true;
        }
    }

    public final boolean a(List arg13, String[] arg14) {
        boolean v1_1;
        EntryItem v2;
        Cursor v9;
        long v10;
        boolean v0;
        synchronized (this) {
            if (arg13 == null) {
                return false;
            }

            try {
                v10 = System.currentTimeMillis();
                v9 = null;
                if (!this.isSQLiteDatabaseAvailable()) {
                    return false;
                }
                Cursor v0_3 = null;
                v0_3 = this.mSQLiteDatabase.query("misc_kv", i, "name=?", new String[]{"subscribe_list"}, null, null, null, "1");
                if (v0_3.moveToNext()) {
                    arg14[0] = v0_3.getString(2);
                }
                v0_3.close();
                v0_3 = null;
                v0_3 = this.mSQLiteDatabase.rawQuery(h, null);
                while (true) {
                    if (!v0_3.moveToNext()) {
                        closeQuietly(v0_3);
                        if (Logger.debug()) {
                            Logger.v("DBHelper", "end querySubscribeList: time=" + (System.currentTimeMillis() - v10) + ", count=" + arg13.size());
                        }
                        return true;
                    }

                    v2 = EntryItem.obtain(v0_3.getLong(0));
                    v2.mName = v0_3.getString(1);
                    v2.mDescription = v0_3.getString(2);
                    v2.mIconUrl = v0_3.getString(3);
                    v2.mType = v0_3.getInt(4);
                    if (v0_3.getInt(5) > 0) {
                        v1_1 = true;
                    } else {
                        v1_1 = false;
                    }
                    v2.mShowNewTip = v1_1;
                    v2.mSubscribeCount = v0_3.getInt(6);
                    if (v0_3.getInt(7) > 0) {
                        v1_1 = true;
                    } else {
                        v1_1 = false;
                    }
                    v2.setSubscribed(v1_1);
                    v2.mWapUrl = v0_3.getString(8);
                    v2.mGroupId = v0_3.getLong(9);
                    com.ss.android.article.base.feature.subscribe.model.d v1_2 = new com.ss.android.article.base.feature.subscribe.model.d(v2);
                    v1_2.badge = v0_3.getInt(12);
                    v1_2.itemDescription = v0_3.getString(13);
                    v1_2.lastTime = v0_3.getLong(14);
                    arg13.add(v1_2);
                    continue;
                }
            } catch (Throwable v1) {
                return false;
            }
        }
    }

    public final void deleteArticle(AbsArticle absArticle) {
        if (absArticle != null
                && absArticle.opItemType == ItemType.ARTICLE
                && absArticle.groupId > 0) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(107));
            contentValues.put("item_id", Long.valueOf(absArticle.groupId));
            contentValues.put("group_item_id", Long.valueOf(absArticle.itemId));
            this.asyncUpdate(contentValues);
        }
    }

    private static Article parseArticleFromCursor(Cursor cursor) {
        Article article = new Article(cursor.getLong(0), cursor.getLong(1), cursor.getInt(2));
        article.tag = cursor.getString(3);
        article.level = cursor.getInt(4);
        article.behotTime = cursor.getLong(5);
        article.shareUrl = cursor.getString(6);
        article.diggCount = cursor.getInt(7);
        article.buryCount = cursor.getInt(8);
        article.repinCount = cursor.getInt(9);
        article.commentCount = cursor.getInt(10);
        article.userDigg = cursor.getLong(11) > 0;
        article.userBury = cursor.getLong(12) > 0;
        article.userRepin = cursor.getLong(13) > 0;
        article.userRepinTime = cursor.getLong(14);
        article.source = cursor.getString(15);
        article.title = cursor.getString(16);
        article.url = cursor.getString(17);
        article.city = cursor.getString(18);
        article.keywords = cursor.getString(19);
        article.publishTime = cursor.getLong(20);
        article.hot = cursor.getInt(21);
        article.hasImage = cursor.getInt(23) > 0;
        article.hasVideo = cursor.getInt(24) > 0;
        article._abstract = cursor.getString(25);
        String image_list = cursor.getString(26);
        String commentJson = cursor.getString(27);
        String largeImageJson = cursor.getString(28);
        String middleImageJson = cursor.getString(29);
        article.groupType = cursor.getInt(30);
        article.subjectLabel = cursor.getString(31);
        article.itemVersion = cursor.getLong(32);
        article.subjectGroupId = cursor.getLong(33);
        article.articleType = cursor.getInt(34);
        article.articleSubType = cursor.getInt(35);
        article.articleUrl = cursor.getString(36);
        article.articleAltUrl = cursor.getString(37);
        article.displayUrl = cursor.getString(38);
        article.displayTitle = cursor.getString(39);
        article.preloadWeb = cursor.getInt(40);
        article.mBanComment = cursor.getInt(41) > 0;
        article.natantLevel = cursor.getInt(42);
        article.groupFlags = cursor.getInt(43);
        article.tcHeadText = cursor.getString(44);
        article.openUrl = cursor.getString(45);
        article.clickTimestamp = cursor.getLong(46);
        article.webTypeLoadTime = cursor.getLong(47);
        article.webTcLoadTime = cursor.getLong(48);
        article.statsTimestamp = cursor.getLong(49);
        article.userDislike = cursor.getInt(50) > 0;
        article.extJson = cursor.getString(51);
        if (!android.support.design.a.isTextEmpty(article.extJson)) {
            try {
                JSONObject jo = new JSONObject(article.extJson);
                article.videoId = jo.optString("video_id");
                article.videoDuration = jo.optInt("video_duration");
                article.adVideoClickTrackUrlsJson = jo.optString("ad_video_click_track_urls");
                article.adVideoClickTrackUrls = BaseAdsData.a(article.adVideoClickTrackUrlsJson);
                article.impressionTimestamp = jo.optLong("impression_timestamp");
                article.mediaName = jo.optString("media_name");
                article.isOriginal = jo.optBoolean("is_original");
                article.reason = jo.optString("reason");
                article.userLike = jo.optBoolean("user_like");
                article.likeCount = jo.optInt("like_count");
                article.mediaInfoJson = jo.optString("media_info");
                article.gallaryImageCount = jo.optInt("gallary_image_count");
                article.gallaryFlag = jo.optInt("gallary_flag");
                if (!android.support.design.a.isTextEmpty(article.mediaInfoJson)) {
                    article.mediaInfo = MediaInfo.fromJO(new JSONObject(article.mediaInfoJson));
                }

                article.userInfoJson = jo.optString("user_info");
                if (!android.support.design.a.isTextEmpty(article.userInfoJson)) {
                    article.userInfo = UgcUser.extractFromUserInfoJson(new JSONObject(article.userInfoJson));
                }

                article.entityStyle = jo.optInt("entity_style");
                article.entityId = jo.optLong("entity_id");
                article.entityWord = jo.optString("entity_word");
                article.entityText = jo.optString("entity_text");
                article.entityMarkJson = jo.optString("entity_mark");
                article.tinyToutiaoUrl = jo.optString("tiny_toutiao_url");
                if (article.entityMarkJson != null && article.entityMarkJson.length() > 0) {
                    article.entityMark = Article.parseEntityMark(new JSONArray(article.entityMarkJson));
                }
                article.entityFollowed = jo.optInt("entity_followed");
                article.entityScheme = jo.optString("entity_scheme");
                article.concernId = jo.optLong("concern_id");
                article.commentsJson = jo.optString("comments");
                if (!android.support.design.a.isTextEmpty(article.commentsJson)) {
                    article.setCommentsJSONArray(new JSONArray(article.commentsJson));
                }
                article.zzcommentJson = jo.optString("zzcomment");
                if (!android.support.design.a.isTextEmpty(article.zzcommentJson)) {
                    article.c(new JSONArray(article.zzcommentJson));
                }
                article.videoDetailInfo = jo.optString("video_detail_info");
                if (!android.support.design.a.isTextEmpty(article.videoDetailInfo)) {
                    article.parseVideoDetailInfo(new JSONObject(article.videoDetailInfo));
                }
                article.wapHeaders = jo.optJSONObject("wap_headers");
                article.ignoreWebTransform = jo.optInt("ignore_web_transform", 1) > 0;
                article.mediaUserId = jo.optLong("media_user_id", 0);
            } catch (JSONException e) {
                Logger.d("Article", "exception in parseExtraData : " + e.toString());
            }
        }

        article.imageList1 = "";
        article.imageList = null;
        if (!android.support.design.a.isTextEmpty(image_list)) {
            try {
                article.parseImageList(new JSONArray(image_list));
            } catch (Exception exception) {
                Logger.v("DBHelper", "parse image_list exception: " + exception);
            }
        }

        article.commentJson = "";
        if (!android.support.design.a.isTextEmpty(commentJson)) {
            try {
                article.parseComment(new JSONObject(commentJson));
                if (article.comment != null) {
                    article.commentJson = commentJson;
                }
            } catch (Exception exception) {
            }
        }

        article.largeImageJson = "";
        if (!android.support.design.a.isTextEmpty(largeImageJson)) {
            try {
                JSONArray jsonArray = new JSONArray(largeImageJson);
                if (jsonArray.length() > 0) {
                    article.largeImageList = ImageInfo.fromJson(jsonArray.getJSONObject(0), true);
                    if (article.largeImageList != null) {
                        article.largeImageJson = largeImageJson;
                    }
                }
            } catch (Exception exception) {
            }
        }

        article.middleImageJson = "";
        if (!android.support.design.a.isTextEmpty(middleImageJson)) {
            try {
                article.middleImage = ImageInfo.fromJson(new JSONObject(middleImageJson), false);
                if (article.middleImage != null) {
                    article.middleImageJson = middleImageJson;
                } else {
                    return article;
                }
            } catch (Exception exception) {
            }
        }

        return article;
    }

    private long getSearchWordList(int type, String searchWord) {
        Cursor cursor = null;
        synchronized (this) {
            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    return -1L;
                }
                String[] selection = new String[3];
                selection[0] = "id";
                selection[1] = "type";
                selection[2] = "search_word";
                cursor = this.mSQLiteDatabase.query("search_word",
                        selection,
                        "type=? and search_word=?",
                        new String[]{String.valueOf(type), searchWord},
                        null,
                        null,
                        "timestamp DESC");
                if (cursor.getCount() <= 0) {
                    return -1;
                }
                cursor.moveToFirst();
                return cursor.getLong(cursor.getColumnIndex("id"));
            } catch (Exception exception) {
                Logger.w("DBHelper", "get search word list error:" + exception);
                return -1;
            } finally {
                closeQuietly(cursor);
            }
        }
    }

    private synchronized List<Article> queryRecentOrFavor0(long userRepinTime, int limit) {
        return this.queryRecentOrFavor(userRepinTime, limit);
    }

    public final int insertFavorList(List arg24) {
        ContentValues v2_3;
        boolean v8_1;
        long v16;
        int v7;
        int v8;
        int v9;
        String v5;
        Object v11;
        Cursor v13;
        Iterator v14;
        String[] v6;
        String[] v4;
        Cursor v3 = null;
        synchronized (this) {
            try {
                if (arg24.isEmpty()) {
                    return 0;
                }
                if (!this.isSQLiteDatabaseAvailable()) {
                    return 0;
                }
                int v12 = 0;
                this.mSQLiteDatabase.beginTransaction();
                v4 = new String[]{"user_repin", "user_repin_time", "user_dislike", "read_timestamp", "item_version"};
                v6 = new String[1];
                v14 = arg24.iterator();
                v13 = v3;
                while (true) {
                    if (!v14.hasNext()) {
                        break;
                    }

                    v11 = v14.next();
                    ((Article) v11).userRepin = true;
                    if (((Article) v11).itemId > 0) {
                        v5 = "group_item_id =? ";
                        v6[0] = String.valueOf(((Article) v11).itemId);
                    } else {
                        v5 = "item_id =? ";
                        v6[0] = String.valueOf(((Article) v11).groupId);
                    }

                    v3 = this.mSQLiteDatabase.query(
                            "v30_article",
                            v4,
                            v5,
                            v6,
                            null,
                            null,
                            null,
                            "1");
                    v9 = 0;
                    v8 = 0;
                    int v2_1 = 1;
                    v7 = 0;
                    if (v3.moveToNext()) {
                        if (v3.getInt(0) > 0) {
                            v9 = 1;
                        } else {
                            v9 = 0;
                        }
                        v16 = v3.getLong(1);
                        if (v3.getInt(2) > 0) {
                            v8_1 = true;
                        } else {
                            v8_1 = false;
                        }
                        ((Article) v11).userDislike = v8_1;
                        ((Article) v11).clickTimestamp = v3.getLong(3);
                        long v18 = v3.getLong(4);
                        v8 = 1;
                        if (v9 != 0) {
                            if (v9 != 0) {
                                if (v16 > ((Article) v11).userRepinTime) {
                                    ((Article) v11).userRepinTime = v16;
                                }
                            }
                        } else if (v16 > ((Article) v11).userRepinTime) {
                            v8 = 0;
                            v2_1 = 0;
                        } else {
                            if (v9 != 0) {
                                if (v16 > ((Article) v11).userRepinTime) {
                                    ((Article) v11).userRepinTime = v16;
                                }
                            }
                        }
                        if ((((Article) v11).a(v18)) && ((((Article) v11).userDislike) || ((Article) v11).clickTimestamp > 0)) {
                            v7 = 1;
                            v8 = 1;
                        }

                        if (v9 != 0) {
                            v2_1 = 0;
                        }

                        v9 = 1;
                        int v22 = v7;
                        v7 = v2_1;
                        v2_1 = v22;
                    } else {
                        v7 = 1;
                        v2_1 = 0;
                    }
                    v3.close();
                    if (v7 != 0) {
                        ++v12;
                    }
                    if (v9 == 0) {
                        if ((v11 instanceof Article)) {
                            v2_3 = article2ContentValues(((Article) v11), false, false);
                        } else {
                            v2_3 = null;
                        }
                        if (v2_3 == null) {

                        } else {
                            this.mSQLiteDatabase.insert("v30_article", null, v2_3);
                        }
                    } else if (v8 != 0) {
                        ContentValues v7_1 = new ContentValues();
                        v7_1.put("user_repin", Boolean.valueOf(((Article) v11).userRepin));
                        v7_1.put("user_repin_time", Long.valueOf(((Article) v11).userRepinTime));
                        if (v2_1 != 0) {
                            ((Article) v11).clickTimestamp = 0;
                            ((Article) v11).userDislike = false;
                            v7_1.put("read_timestamp", Long.valueOf(0));
                            v7_1.put("user_dislike", Integer.valueOf(0));
                        }
                        this.mSQLiteDatabase.update("v30_article", v7_1, v5, v6);
                    }
                    v13 = v3;
                    continue;
                }
                this.mSQLiteDatabase.setTransactionSuccessful();
                return v12;
            } catch (Exception v2_2) {
                Logger.w("DBHelper", "insert favorlist: " + v2_2);
                return 0;
            } finally {
                closeQuietlyAndEndTransaction(v3, this.mSQLiteDatabase);
            }
        }
    }

    public final SQLiteDatabase createSQLiteDatabase(Context context) {
        try {
            return new DBOpenHelper(context).getWritableDatabase();
        } catch (Exception e) {
            return null;
        }
    }

    public final f b(long arg14) {
        Cursor v9_1;
        f v1_1;
        int v8;
        String v7;
        String v6;
        int v5;
        String v4;
        Cursor cursor = null;
        f v0;
        f v9 = null;
        if (!this.isSQLiteDatabaseAvailable()) {
            v0 = v9;
            return v0;
        }

        try {
            cursor = this.mSQLiteDatabase.query("net_request_queue",
                    new String[]{"key", "type", "url", "request_method", "entity_json", "extra", "retry_count", "time"},
                    "time> ?",
                    new String[]{String.valueOf(arg14)}, null, null, "time ASC", "1");
            if (cursor.moveToNext()) {
                String v0_3 = cursor.getString(0);
                int v3 = cursor.getInt(1);
                v4 = cursor.getString(2);
                v5 = cursor.getInt(3);
                v6 = cursor.getString(4);
                v7 = cursor.getString(5);
                v8 = cursor.getInt(6);
                v1_1 = new f(v3, v0_3, cursor.getLong(7));
                v1_1.mUrl = v4;
                v1_1.mRequestMethod = v5;
                v1_1.mEentityJson = v6;
                v1_1.mExtraJson = v7;
                v1_1.retry_count = v8;
                v0 = v1_1;
                return v0;
            } else {
                return v9;
            }
        } catch (Exception v0_2) {
            Logger.throwExceptionInDebug(v0_2);
            return null;
        } finally {
            if (cursor != null) {
                try {
                    cursor.close();
                } catch (Exception e) {
                }
            }
        }
    }

    public final String queryPostContentHint(String categoryNameOrConcernId, int refer) {
        String[] columns = new String[]{"post_content_hint"};
        String selection = refer == 1 ? "category_name=?" : "concern_id=?";
        String[] selectionArgs = new String[]{categoryNameOrConcernId};
        try {
            Cursor cursor = this.mSQLiteDatabase.query("v38_category_meta", columns, selection, selectionArgs, null, null, null);
            if (cursor == null) {
                return "";
            }
            if (!cursor.moveToFirst()) {
                return "";
            }
            String postContentHint = cursor.getString(0);
            closeQuietly(cursor);
            return postContentHint;
        } catch (Exception exception) {
            Logger.w("DBHelper", "query category show et status exception: " + exception);
        }

        return "";
    }

    public final List<String> getCityList(int type) {
        Cursor cursor = null;
        ArrayList<String> cityList = null;
        synchronized (this) {
            try {
                cityList = new ArrayList();
                if (!this.isSQLiteDatabaseAvailable()) {
                    return cityList;
                }
                int v0_2 = 3;
                String[] columns = new String[v0_2];
                columns[0] = "type";
                columns[1] = "search_word";
                columns[2] = "timestamp";
                cursor = this.mSQLiteDatabase.query("search_word",
                        columns,
                        "type=?",
                        new String[]{String.valueOf(type)},
                        null,
                        null,
                        "timestamp DESC",
                        "5");
                while (cursor.moveToNext()) {
                    cityList.add(cursor.getString(cursor.getColumnIndex("search_word")));
                }
                return cityList;
            } catch (Exception exception) {
                Logger.w("DBHelper", "get city list error:" + exception);
                return cityList;
            } finally {
                closeQuietly(cursor);
            }
        }
    }

    public final void clearSubscribe() {
        synchronized (this) {
            try {
                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }
                Logger.v("DBHelper", "clearSubscribe");
                this.mSQLiteDatabase.beginTransaction();
                String[] whereArgs = new String[]{"-1"};
                this.mSQLiteDatabase.delete("v27_entry_group", "e_group_id=?", whereArgs);
                String[] whereArgs2 = new String[]{"subscribe_list"};
                this.mSQLiteDatabase.delete("misc_kv", "name=?", whereArgs2);
                ContentValues contentValues = new ContentValues();
                contentValues.put("is_subscribe", Integer.valueOf(0));
                this.mSQLiteDatabase.update("v27_entry", contentValues, null, null);
                this.mSQLiteDatabase.setTransactionSuccessful();
            } catch (Exception exception) {
                Logger.w("DBHelper", "clearSubscribe exception: " + exception);
            } finally {
                closeQuietlyAndEndTransaction(null, this.mSQLiteDatabase);
            }
        }
    }

    public final void b(f arg5) {
        ContentValues contentValues = new ContentValues();
        contentValues.put("ss_op_key", Integer.valueOf(12));
        contentValues.put("type", Integer.valueOf(arg5.mType));
        contentValues.put("key", arg5.mKey);
        contentValues.put("url", arg5.mUrl);
        contentValues.put("entity_json", arg5.mEentityJson);
        contentValues.put("extra", arg5.mExtraJson);
        contentValues.put("request_method", Integer.valueOf(arg5.mRequestMethod));
        contentValues.put("retry_count", Integer.valueOf(arg5.retry_count));
        contentValues.put("time", Long.valueOf(arg5.mTime));
        this.asyncUpdate(contentValues);
    }

    public synchronized final void deleteArticleContent(AbsArticle article) {
        if (article != null) {
            try {
                if (article.opItemType != ItemType.ARTICLE) {
                    return;
                }

                if (article.groupId <= 0) {
                    return;
                }

                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }

                String[] whereArgs = new String[2];
                whereArgs[0] = String.valueOf(article.groupId);
                whereArgs[1] = String.valueOf(article.itemId);
                this.mSQLiteDatabase.delete("v30_detail", "group_id =?  AND item_id = ?", whereArgs);
            } catch (Exception exception) {
                Logger.w("DBHelper", "delete article content exception: " + exception);

            }
        }
    }

    private List<Article> queryRecentOrFavor(long userRepinTime, int limit) {
        Cursor cursor = null;
        String selection;
        String[] selectionArgs;
        String limitString;
        String orderBy;
        String table;
        ArrayList<Article> articleList = null;
        Cursor v10 = null;
        synchronized (this) {
            try {
                articleList = new ArrayList();
                if (!this.isSQLiteDatabaseAvailable()) {
                    return articleList;
                }
                table = "v30_article";
                orderBy = "user_repin_time" + " DESC";
                limitString = String.valueOf(limit);
                StringBuilder stringBuilder = new StringBuilder();
                if (!android.support.design.a.isTextEmpty(null)) {
                    if (userRepinTime > 0L) {
                        stringBuilder.append("tag=? AND ").append("user_repin_time").append(" < ?");
                        selectionArgs = new String[]{null, String.valueOf(userRepinTime)};
                    } else {
                        stringBuilder.append("tag=?");
                        selectionArgs = new String[]{null};
                    }
                } else if (userRepinTime > 0L) {
                    stringBuilder.append("user_repin_time").append(" < ?");
                    selectionArgs = new String[]{String.valueOf(userRepinTime)};
                } else {
                    selectionArgs = null;
                }
                if (stringBuilder.length() > 0) {
                    stringBuilder.append(" AND ");
                }
                stringBuilder.append("user_repin > 0");

                if (!android.support.design.a.isTextEmpty(null)) {
                    if (stringBuilder.length() > 0) {
                        stringBuilder.append(" AND ");
                    }
                    stringBuilder.append((String) null);
                }

                if (stringBuilder.length() > 0) {
                    selection = stringBuilder.toString();
                } else {
                    selection = null;
                }
                cursor = this.mSQLiteDatabase.query(table, v30_article_colums, selection, selectionArgs, null, null, orderBy, limitString);
                while (true) {
                    if (!cursor.moveToNext()) {
                        return articleList;
                    }
                    articleList.add(parseArticleFromCursor(cursor));
                }
            } catch (Exception exception) {
                Logger.w("DBHelper", "queryRecentOrFavor exception " + exception);
                return articleList;
            } finally {
                if (cursor != null) {
                    try {
                        cursor.close();
                    } catch (Exception e) {

                    }
                }
            }
        }
    }

    private static EntryItem fromCursor(Cursor cursor) {
        EntryItem entryItem = EntryItem.obtain(cursor.getLong(0));
        entryItem.mName = cursor.getString(1);
        entryItem.mDescription = cursor.getString(2);
        entryItem.mIconUrl = cursor.getString(3);
        entryItem.mType = cursor.getInt(4);
        entryItem.mShowNewTip = cursor.getInt(5) > 0;
        entryItem.mSubscribeCount = cursor.getInt(6);
        entryItem.setSubscribed(cursor.getInt(7) > 0);
        entryItem.mWapUrl = cursor.getString(8);
        entryItem.mGroupId = cursor.getLong(9);
        entryItem.mUserId = cursor.getLong(11);
        return entryItem;
    }

    public final int insertEntryGroupList(List<EntryGroup> entryItemList) {
        Cursor v2_4;
        int v5_1;
        int v6_1;
        Iterator v11_1;
        ContentValues v10_1;
        int v3;
        String[] v6;
        long v8;
        int v4 = 0;
        synchronized (this) {
            if (Logger.debug()) {
                Logger.d("DBHelper", "begin insertEntryGroupList");
            }

            v8 = System.currentTimeMillis();
            if (entryItemList != null && entryItemList.size() != 0) {
                if (!this.isSQLiteDatabaseAvailable()) {
                    return 0;
                }
            } else {
                return 0;
            }
            this.mSQLiteDatabase.beginTransaction();
            String v5 = "id=?";
            v6 = new String[]{"0"};
            Iterator<EntryGroup> v7 = entryItemList.iterator();
            v3 = 0;

            while (true) {
                Object v2_3;
                if (v7.hasNext()) {
                    Iterator<EntryItem> entryItemIterator = v7.next().c.iterator();
                    while (true) {
                        if (!entryItemIterator.hasNext()) {
                            break;
                        }
                        v2_3 = entryItemIterator.next();
                        v6[0] = String.valueOf(((EntryItem) v2_3).mId);
                        ContentValues contentValues = entryItem2ContentValues(true, ((EntryItem) v2_3), ((EntryItem) v2_3).isSubscribed());
                        if (this.mSQLiteDatabase.update("v27_entry", contentValues, v5, v6) <= 0) {
                            contentValues.put("id", Long.valueOf(((EntryItem) v2_3).mId));
                            this.mSQLiteDatabase.insert("v27_entry", null, contentValues);
                        }
                        ++v3;
                    }
                } else {
                    this.mSQLiteDatabase.delete("v27_entry_group_meta", null, null);
                    this.mSQLiteDatabase.delete("v27_entry_group", "e_group_id>0", null);
                    v10_1 = new ContentValues();
                    v11_1 = entryItemList.iterator();
                    v6_1 = 0;
                    v5_1 = v3;
                    int v2_1;
                    try {
                        while (true) {
                            if (v11_1.hasNext()) {
                                Object v3_1 = v11_1.next();
                                v10_1.clear();
                                v10_1.put("id", Long.valueOf(((EntryGroup) v3_1).id));
                                v10_1.put("name", ((EntryGroup) v3_1).name);
                                v10_1.put("list_order", Integer.valueOf(v6_1));
                                ++v6_1;
                                this.mSQLiteDatabase.insert("v27_entry_group_meta", null, v10_1);
                                Iterator v12 = ((EntryGroup) v3_1).c.iterator();
                                int v7_1;
                                for (v7_1 = 0; true; ++v7_1) {
                                    if (!v12.hasNext()) {
                                        break;
                                    }
                                    v2_3 = v12.next();
                                    v10_1.clear();
                                    v10_1.put("e_group_id", Long.valueOf(((EntryGroup) v3_1).id));
                                    v10_1.put("e_entry_id", Long.valueOf(((EntryItem) v2_3).mId));
                                    v10_1.put("e_list_order", Integer.valueOf(v7_1));
                                    this.mSQLiteDatabase.insert("v27_entry_group", null, v10_1);
                                    ++v5_1;
                                }
                            } else {
                                break;
                            }
                        }
                        this.mSQLiteDatabase.setTransactionSuccessful();
                        v2_4 = null;
                        closeQuietlyAndEndTransaction(v2_4, this.mSQLiteDatabase);
                        v2_1 = v5_1;
                    } catch (Exception v2_2) {
                        v4 = v5_1;
                        Logger.w("DBHelper", "insert group list: " + v2_2);
                        v2_4 = null;
                        closeQuietlyAndEndTransaction(v2_4, this.mSQLiteDatabase);
                        v2_1 = v4;
                    }

                    if (Logger.debug()) {
                        Logger.v("DBHelper", "end insertEntryGroupList: time=" + (System.currentTimeMillis() - v8) + ", count=" + v2_1);
                    }
                    return v2_1;
                }
            }
        }
    }

    public final String queryCategoryConcernInfo(String categoryOrConcernId, int arg11) {
        String[] columns = new String[]{"concern_info"};
        String selection = arg11 == 1 ? "category_name=?" : "concern_id=?";
        String[] selectionArgs = new String[]{categoryOrConcernId};
        try {
            Cursor cursor = this.mSQLiteDatabase.query("v38_category_meta", columns, selection, selectionArgs, null, null, null);
            if (cursor == null) {
                return null;
            }

            if (!cursor.moveToFirst()) {
                return null;
            }

            String concernInfo = cursor.getString(0);
            closeQuietly(cursor);
            return concernInfo;
        } catch (Exception exception) {
            Logger.w("DBHelper", "query category concern info exception: " + exception);
        }

        return null;
    }

    public final List<EntryGroup> queryEntryGroupList() {
        Cursor cursor = null;
        long queryStartTs;
        ArrayList<EntryGroup> result;
        synchronized (this) {
            result = new ArrayList();
            queryStartTs = System.currentTimeMillis();
            if (this.isSQLiteDatabaseAvailable()) {

            } else {
                return result;
            }
        }
        try {
            cursor = this.mSQLiteDatabase.query(
                    "v27_entry_group_meta",
                    new String[]{"id", "name"},
                    null,
                    null,
                    null,
                    null,
                    "list_order");
            while (cursor.moveToNext()) {
                long id = cursor.getLong(0);
                String name = cursor.getString(1);
                if (id <= 0) {
                    continue;
                }

                if (android.support.design.a.isTextEmpty(name)) {
                    continue;
                }

                EntryGroup entryGroup = new EntryGroup();
                entryGroup.id = id;
                entryGroup.name = name;
                result.add(entryGroup);
            }
        } catch (Exception exception) {
            Logger.w("DBHelper", "queryEntryGroupList exception: " + exception);
        } finally {
            closeQuietly(cursor);
            long costTime = System.currentTimeMillis() - queryStartTs;
            if (Logger.debug()) {
                Logger.d("DBHelper", "queryEntryGroupList time " + costTime);
            }
        }
        return result;
    }

    public final List<EntryItem> queryEntryGroup(long arg12) {
        synchronized (this) {
            if (Logger.debug()) {
                Logger.d("DBHelper", "begin queryEntryGroup");
            }
            long startTime = System.currentTimeMillis();
            ArrayList<EntryItem> result = new ArrayList<>();
            if (this.isSQLiteDatabaseAvailable()) {
                Cursor cursor = null;
                try {
                    cursor = this.mSQLiteDatabase.rawQuery(SELECT_ENTRY_GROUP_SQL, new String[]{String.valueOf(arg12)});
                    while (cursor.moveToNext()) {
                        EntryItem entryItem = fromCursor(cursor);
                        if (entryItem.mId <= 0) {
                            continue;
                        }
                        result.add(entryItem);
                    }
                    closeQuietly(cursor);
                    if (Logger.debug()) {
                        Logger.v("DBHelper", "end queryEntryGroup: time=" + (System.currentTimeMillis() - startTime) + ", count=" + ((List) result).size());
                    }
                    return result;
                } catch (Throwable throwable) {
                    Logger.w("DBHelper", "queryEntryGroup exception: " + throwable);
                } finally {
                    closeQuietly(cursor);
                    return result;
                }
            }
            return result;
        }
    }

    final void cleanV30Article() {
        int v1 = 0;
        long v0_1;
        Cursor v2;
        long v10 = 0;
        com.ss.android.l.c.a();
        com.ss.android.l.c.b();
        try {
            v2 = this.mSQLiteDatabase.query("v30_article", new String[]{"max_behot_time"}, "user_repin != 1", null, null, null, "max_behot_time DESC", "1800,1");
            if (v2.moveToNext()) {
                v0_1 = v2.getLong(0);
            } else {
                v0_1 = v10;
            }
            v2.close();
            com.ss.android.l.c.c();
            String v2_1 = "max_behot_time <= ? AND user_repin != 1";
            String[] v3 = new String[]{String.valueOf(v0_1)};
            if (v0_1 > v10) {
                v1 = this.mSQLiteDatabase.delete("v30_article", v2_1, v3);
            } else {
                v1 = 0;
            }
            com.ss.android.l.c.c();
        } catch (Exception exception) {
            Logger.w("DBHelper", "clean list exception: " + exception);
        }

        if (v1 > 0) {
            try {
                this.mSQLiteDatabase.execSQL("DELETE FROM v30_detail WHERE NOT EXISTS (SELECT * FROM v30_article WHERE v30_article.item_id = v30_detail.group_id AND v30_article.group_item_id = v30_detail.item_id)");
                com.ss.android.l.c.c();
            } catch (Exception e) {
                Logger.w("DBHelper", "clean detail exception: " + e);
            }
        }
    }

    public final EntryItem d(long arg12) {
        Cursor v1;
        EntryItem v0_3;
        EntryItem v9 = null;
        synchronized (this) {
            if (this.isSQLiteDatabaseAvailable()) {
                try {
                    v1 = this.mSQLiteDatabase.query("v27_entry", e, "id=?", new String[]{String.valueOf(arg12)}, null, null, null, "1");
                    if (v1.moveToNext()) {
                        v0_3 = fromCursor(v1);
                        if (v0_3.mId <= 0) {

                        } else {
                            closeQuietly(v1);
                            return v0_3;
                        }
                    }
                    closeQuietly(v1);
                    return v9;
                } catch (Exception v0_1) {
                    Logger.w("DBHelper", "queryEntryItem exception: " + v0_1);
                } finally {
                    return v9;
                }
            }
            return null;
        }
    }

    public final void syncReadTs(AbsArticle absArticle) {
        if (absArticle != null) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("ss_op_key", Integer.valueOf(1));
            contentValues.put("op_item_type", Integer.valueOf(absArticle.opItemType.getValue()));
            contentValues.put("item_id", Long.valueOf(absArticle.groupId));
            contentValues.put("group_item_id", Long.valueOf(absArticle.itemId));
            contentValues.put("read_timestamp", Long.valueOf(absArticle.clickTimestamp));
            this.asyncUpdate(contentValues);
        }
    }

    public final boolean e(AbsArticle absArticle) {
        synchronized (this) {
            Article article = this.a(absArticle);
            if (article == null) {
                return false;
            } else if (article.clickTimestamp <= 0) {
                return false;
            } else {
                return true;
            }
        }
    }

    final void cleanCategory() {
        long v4_1;
        String[] v15;
        String v14;
        HashSet v2_2;
        Cursor cursor = null;
        long v12 = 0;
        Cursor v11 = null;
        com.ss.android.l.c.a();
        com.ss.android.l.c.b();
        try {
            this.mSQLiteDatabase.beginTransaction();
            cursor = this.mSQLiteDatabase.rawQuery("SELECT DISTINCT(category) FROM v30_category_list", null);
            v2_2 = new HashSet();
            while (cursor.moveToNext()) {
                String v4 = cursor.getString(0);
                if (android.support.design.a.isTextEmpty(v4)) {
                    continue;
                }
                v2_2.add(v4);
            }
            cursor.close();

            com.ss.android.l.c.c();
            v14 = "category=? AND cate_behot_time<=?";
            v15 = new String[]{"", ""};
            Iterator v16 = v2_2.iterator();
            while (true) {
                if (!v16.hasNext()) {
                    break;
                }
                Object v10 = v16.next();
                v15[0] = ((String) v10);
                if (this.A == null) {
                    this.A = SQLiteQueryBuilder.buildQueryString(false, "v30_category_list",
                            new String[]{"cate_behot_time"}, "category=? ", null, null, "cate_behot_time DESC", null);
                }

                StringBuilder v3_1 = new StringBuilder();
                int v2_3 = "__all__".equals(v10) ? 500 : 200;
                cursor = this.mSQLiteDatabase.rawQuery(this.A + " LIMIT " + v3_1.append(v2_3).append(", 1").toString(), new String[]{(String) v10});
                if (cursor.moveToNext()) {
                    v4_1 = cursor.getLong(0);
                } else {
                    v4_1 = v12;
                }
                cursor.close();
                if (v4_1 <= v12) {

                } else {
                    v15[1] = String.valueOf(v4_1);
                    this.mSQLiteDatabase.delete("v30_category_list", v14, v15);
                }
                continue;
            }
            this.mSQLiteDatabase.setTransactionSuccessful();
            com.ss.android.l.c.c();
        } catch (Exception v2_1) {
            Logger.w("DBHelper", "clean category exception: " + v2_1);
        } finally {
            closeQuietlyAndEndTransaction(cursor, this.mSQLiteDatabase);
        }
    }

    final void shrinkCategoryMeta(long arg10) {
        if (this.mSQLiteDatabase != null) {
            com.ss.android.l.c.a();
            com.ss.android.l.c.b();
            try {
                String[] v2 = new String[]{"category_name"};
                String v3 = "refresh_time < " + (arg10 - 604800000);
                Cursor v0_1 = this.mSQLiteDatabase.query("v38_category_meta", v2, v3, null, null, null, "refresh_time DESC");
                StringBuilder v1 = new StringBuilder();
                while (v0_1.moveToNext()) {
                    if (v1.length() > 0) {
                        v1.append(",");
                    }

                    v1.append(v0_1.getString(0));
                }
                com.ss.android.l.c.c();
                closeQuietly(v0_1);
                this.mSQLiteDatabase.delete("v30_category_list", "category IN (?)", new String[]{v1.toString()});
                com.ss.android.l.c.c();
                this.mSQLiteDatabase.delete("v38_category_meta", v3, null);
                com.ss.android.l.c.c();
            } catch (Exception v0) {
                Logger.e("DBHelper", "shrink category metalocal");
            }
        }
    }

    private void f(AbsArticle arg5) {
        synchronized (this) {
            try {
                if (arg5.opItemType != ItemType.ARTICLE) {
                    return;
                }

                if (arg5.groupId <= 0) {
                    return;
                }

                if (!this.isSQLiteDatabaseAvailable()) {
                    return;
                }
                int v0_1 = 2;
                String[] v0_3 = new String[v0_1];
                v0_3[0] = String.valueOf(arg5.groupId);
                v0_3[1] = String.valueOf(arg5.itemId);
                this.mSQLiteDatabase.delete("v30_detail", "group_id =?  AND item_id = ?", v0_3);
                this.mSQLiteDatabase.delete("v30_article", "item_id =?  AND group_item_id = ?", v0_3);
                this.mSQLiteDatabase.delete("v30_category_list", "cell_id=? AND cell_type=?", new String[]{arg5.getItemKey(), "0"});
            } catch (Exception v0_2) {
                Logger.w("DBHelper", "delete article exception: " + v0_2);
            }
        }
    }

    final void cleanSearchWord() {
        long v0_1;
        Cursor v2;
        long v10 = 0;
        com.ss.android.l.c.a();
        com.ss.android.l.c.b();
        try {
            v2 = this.mSQLiteDatabase.query("search_word", new String[]{"timestamp"}, null, null, null, null, "timestamp ASC", "50,1");
            if (v2.moveToNext()) {
                v0_1 = v2.getLong(0);
            } else {
                v0_1 = v10;
            }
            closeQuietly(v2);
            com.ss.android.l.c.c();
            String v2_1 = "timestamp <= ? ";
            String[] v3 = new String[]{String.valueOf(v0_1)};
            if (v0_1 > v10) {
                this.mSQLiteDatabase.delete("search_word", v2_1, v3);
            }
            com.ss.android.l.c.c();
        } catch (Exception v0) {
            Logger.w("DBHelper", "clean list exception: " + v0);
        }
    }

    private void g(List arg13) {
        Cursor v1 = null;
        Article v11;
        String[] v2;
        String[] v4;
        Cursor v9 = null;
        synchronized (this) {
            if (arg13.isEmpty()) {
                return;
            }

            if (this.isSQLiteDatabaseAvailable()) {
                int v0_1 = 2;
                try {
                    v4 = new String[v0_1];
                    v4[0] = "0";
                    v4[1] = "0";
                    v2 = new String[]{"group_id"};
                    Iterator v10 = arg13.iterator();
                    while (true) {
                        if (!v10.hasNext()) {
                            break;
                        }

                        Object v0_3 = v10.next();
                        v11 = ((CellRef) v0_3).article;
                        if (((CellRef) v0_3).cellType != 0) {
                            continue;
                        }

                        if (v11 == null) {
                            continue;
                        }

                        v4[0] = String.valueOf(v11.groupId);
                        v4[1] = String.valueOf(v11.itemId);
                        v1 = this.mSQLiteDatabase.query("v30_detail", v2,
                                "group_id =?  AND item_id = ?", v4,
                                null, null, null, "1");
                        if (v1.moveToNext()) {
                            v11.isDetailLoaded = true;
                        }
                        v1.close();
                        continue;
                    }
                } catch (Exception v0_2) {
                    Logger.w("DBHelper", "query content load status exception: " + v0_2);
                } finally {
                    closeQuietlyAndEndTransaction(v1, this.mSQLiteDatabase);
                }
            }
        }
    }

    final void cleanV30Essay() {
        long v0_1;
        Cursor v2;
        long v10 = 0;
        com.ss.android.l.c.a();
        com.ss.android.l.c.b();
        try {
            v2 = this.mSQLiteDatabase.query("v30_essay", new String[]{"behot_time"}, "user_repin != 1", null, null, null, "behot_time DESC", "1800,1");
            if (v2.moveToNext()) {
                v0_1 = v2.getLong(0);
            } else {
                v0_1 = v10;
            }
            v2.close();
            com.ss.android.l.c.c();
            String v2_1 = "behot_time <= ? AND user_repin != 1";
            String[] v3 = new String[]{String.valueOf(v0_1)};
            if (v0_1 > v10) {
                this.mSQLiteDatabase.delete("v30_essay", v2_1, v3);
            }

            com.ss.android.l.c.c();
        } catch (Exception v0) {
            Logger.w("DBHelper", "clean list exception: " + v0);
        }
    }

    public final void h() {
        if (System.currentTimeMillis() - this.B >= 7200000 && (this.isSQLiteDatabaseAvailable())) {
            this.b(123, DBHelper.class);
        }
    }

    private void h(long arg6) {
        synchronized (this) {
            if (this.isSQLiteDatabaseAvailable()) {
                if (arg6 > 0) {
                    try {
                        this.mSQLiteDatabase.delete("v30_category_list", "ad_id =?", new String[]{String.valueOf(arg6)});
                    } catch (Exception v0_1) {
                        Logger.w("DBHelper", "delete Ad exception: " + v0_1);
                    }
                }
            }
        }
    }

    private void i() {
        synchronized (this) {
            if (!this.isSQLiteDatabaseAvailable()) {
                return;
            }

            Logger.w("DBHelper", "clear article category list");
            try {
                this.mSQLiteDatabase.delete("v30_category_list", null, null);
                this.mSQLiteDatabase.delete("article_category", null, null);
            } catch (Exception v0_1) {
                Logger.w("DBHelper", "clear article category list exception: " + v0_1);
            }
        }
    }

    private boolean shouldShrink() {
        int count;
        Cursor cursor;
        com.ss.android.l.c.a();
        com.ss.android.l.c.b();
        try {
            cursor = this.mSQLiteDatabase.rawQuery("SELECT COUNT(*) FROM v30_article", null);
            if (cursor.moveToNext()) {
                count = cursor.getInt(0);
            } else {
                count = 0;
            }
            closeQuietly(cursor);
            com.ss.android.l.c.c();
            if (count < 2250) {
                return false;
            }
        } catch (Exception exception) {
            Logger.w("DBHelper", "clean list exception: " + exception);
        }
        return true;
    }

    private void k() {
        Iterator v5;
        Cursor v1_2;
        int v0_1;
        Cursor v10;
        Cursor v2_2 = null;
        Throwable v10_1;
        Throwable v0_2;
        Cursor v0;
        int v1 = 0;
        if (System.currentTimeMillis() - this.B < 7200000) {
            return;
        }

        if (!this.isSQLiteDatabaseAvailable()) {
            return;
        }

        this.B = System.currentTimeMillis();
        JSONObject v3 = new JSONObject();
        JSONObject v4 = new JSONObject();
        Throwable v1_1;
        try {
            v0 = this.mSQLiteDatabase.rawQuery("SELECT name FROM sqlite_master WHERE type=\'table\'", null);
            v3.put("db_path", this.mSQLiteDatabase.getPath());
            v3.put("db_max_size", this.mSQLiteDatabase.getMaximumSize());
            v3.put("db_page_size", this.mSQLiteDatabase.getPageSize());
            v3.put("db_version", this.mSQLiteDatabase.getVersion());
            File v2_3 = new File(this.mSQLiteDatabase.getPath());
            if (v2_3.exists()) {
                long v6 = v2_3.length();
                v3.put("db_size", v6);
                v1 = ((int) (v6 / 1024 / 1024));
            }
            v2_3 = new File(this.mSQLiteDatabase.getPath() + "-journal");
            if (v2_3.exists()) {
                v3.put("db_journal_size", v2_3.length());
            }

            ArrayList v2_4 = new ArrayList();
            if (v0.moveToFirst()) {
                while (!v0.isAfterLast()) {
                    ((List) v2_4).add(v0.getString(0));
                    v0.moveToNext();
                }
            }

            v0.close();
            v3.put("db_table_count", ((List) v2_4).size());
            v5 = ((List) v2_4).iterator();
            v2_2 = v0;
            while (true) {
                if (!v5.hasNext()) {
                    closeQuietly(v2_2);
                    v0_1 = v1;
                    if (Logger.debug()) {
                        Logger.d("DBHelper", "DB Basic Info: " + v3 + "\nDB Table Info: " + v4);
                    }
                    com.bytedance.article.common.a.g.serviceMonitor("new_db_size", v0_1, v4);
                    return;
                }

                Object v0_4 = v5.next();
                v2_2 = this.mSQLiteDatabase.rawQuery("SELECT count(*) FROM " + v0_4, null);
                if (v2_2.moveToFirst()) {
                    while (!v2_2.isAfterLast()) {
                        v4.put(((String) v0_4), v2_2.getString(0));
                        v2_2.moveToNext();
                    }
                }
                v2_2.close();
            }
        } catch (JSONException v0_3) {
            v0_1 = v1;
            v1_2 = v2_2;
            closeQuietly(v1_2);
            if (Logger.debug()) {
                Logger.d("DBHelper", "DB Basic Info: " + v3 + "\nDB Table Info: " + v4);
            }
            com.bytedance.article.common.a.g.serviceMonitor("new_db_size", v0_1, v4);
            return;
        } catch (Exception e) {
            v10_1 = e;
            v0_1 = v1;
            v1_1 = v10_1;
            try {
                v3.put("db_gather_exception", v1_1.toString());
            } catch (JSONException ex) {
                ex.printStackTrace();
            }
            closeQuietly(v2_2);
            if (Logger.debug()) {
                Logger.d("DBHelper", "DB Basic Info: " + v3 + "\nDB Table Info: " + v4);
            }
            com.bytedance.article.common.a.g.serviceMonitor("new_db_size", v0_1, v4);
            return;
        }


    }
}

